Let SQL Server Write Code for You

Many times I happen to find myself in a situation where, as a DBA, I need to write some long and cumbersome code (usually for maintenance purposes). For example: Write a script to copy a bunch of tables from one database to another. Import the tables from one database to another database. Rebuild a bunch of indexes. Update a bunch of statistics. Write scripts for … Continue reading Let SQL Server Write Code for You

Efficiently UPDATE and DELETE using TOP and ORDER BY

Since SQL Server 2005, Microsoft had a nice addition to the common DML statements, UPDATE and DELETE, by allowing the use of the TOP keyword. Well, we’re now in the year 2018 and SQL Server 2019 is just around the corner, and yet unfortunately for many of us, SQL Server still doesn’t support the use of the TOP keyword in direct conjunction with the ORDER … Continue reading Efficiently UPDATE and DELETE using TOP and ORDER BY

Remove the IDENTITY property from an existing column

How to remove the IDENTITY property from an existing column using T-SQL (without changing the order of the columns or moving the data into a new table) Recently I had a scenario at a client where I needed to remove the IDENTITY property of a column in an existing table. The two common methods to do this were quite problematic and were no good for … Continue reading Remove the IDENTITY property from an existing column