How to rename a table or column using T-SQL in Microsoft SQL

So yeah, you could use the Microsoft SQL Server Management Studio UI to rename your table or column. But sometimes you need to do the rename in T-SQL. Here’s how. How to rename a table: EXEC sp_rename 'OldTableName', 'NewTableName' How to rename a column: EXEC sp_rename @objname = 'TableName.OldColumnName', @newname = 'NewColumnName', @objtype = 'COLUMN'...

How to apply UNIQUE constraints to existing SQL columns

I wanted to add this to my blog because I had some difficulty finding out (via Google) how to add a UNIQUE constraint to a SQL column that already existed. To bring you up to speed, UNIQUE constraints prevent duplicate row entries in a column. Note: This pertains to Microsoft SQL Server 2000. To add...

What's the difference between SQL's Truncate Table and Delete From Table?

Thought I’d add a small nugget of SQL knowledge I recently acquired to the blog; the difference between truncate table and delete from table. Both are ways to remove all the rows from a table, but which one should you use? First off, a quick SQL language lesson. SQL statements are divided into two categories:...