How to Drop a SQL Server Constraint When You Don’t Know its Name

If you are looking after a database that has been haphazardly maintained in the past, you might come across inconsistent naming of things such as constraints. When you come to delete the existing one, it might be tricky if it doesn’t have the same name across environments. That’s when you need to do a lookupContinue reading “How to Drop a SQL Server Constraint When You Don’t Know its Name”

Convert a SQL SELECT into an INSERT Script

Sometimes you want to generate an INSERT script from existing data, perhaps with one or two values tweaked. It’s a pain to hand-crank the INSERT when you can see exactly what you want using a SELECT statement. It’s also a bit long-winded to use SQL import/export wizards or other tools. Sometimes, you just want toContinue reading “Convert a SQL SELECT into an INSERT Script”

Simple Modern Paging in SQL Server – Like Skip and Take

If you have been developing SQL Server databases for a while, you may remember performing neat tricks to implement paging. If you haven’t found it yet, there is a simple modern way to do paging in SQL Server that doesn’t require any tricks. For those who have used Linq in C#, you will have comeContinue reading “Simple Modern Paging in SQL Server – Like Skip and Take”

You Can Only Create a User with a Password in a Contained Database

If you attempt to create a user in SQL Server and get the following error: You can only create a user with a password in a contained database You probably didn’t quite configure your database as you intended. You can use the script below to fix it up (substitute DatabaseNameHere with your actual database name.Continue reading “You Can Only Create a User with a Password in a Contained Database”