Little SQL Server Tricks: Rename a Column in Your Table

Naming is important and when you find a more precise one, you not only should update your code but your database as well. SQL Server has the function sp_rename to rename objects in your database.

To rename the column OldName to NewName in your table dbo.MyTable, you can use this command:

Attention: Make sure that you ONLY use the new column name in the second parameter and do not also specify Schema.TableName. Otherwise you will rename the column to something like ‘dbo.MyTable.dbo.MyTable.NewName’.

This little trick will help you to keep your database schema up to date.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.