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...
A Haunting SQL Statement
An interesting thing happened to me yesterday. A coworker came up to me and asked, “Did you write this SQL statement?” After looking at it I realized it was a statement I had written about a year ago. In this statement, I had come up with a clever way of creating what is essentially a...
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:...