Switch a LastChanged datetime to datetime2

For years I’ve been using a datetime column as a “row version” or “time stamp” for most of my SQL tables. The column definition in SQL looks like this: LastChanged datetime NOT NULL DEFAULT (GetDate()) A trigger updates the LastChanged: IF EXISTS (SELECT * FROM sys.triggers WHERE object_id = OBJECT_ID(N’dbo.OnExampleChanged’))…

read more

Switch a database to unicode

So, you have a database with a few hundred char and varchar (ASCII) columns and  you want to take the plunge and convert them all to their nchar and nvarchar unicode equivalents. Start with the following SQL script in SQL Server Management Studio: SELECT t.name AS TableName       ,c.name AS…

read more