At a number of places people have asked me this simple requirement of how can I go about renaming objects inside SQL Server. This can be to rename a Column, Table or even a Database.
There are multiple scenario’s, like in a bulk uploading table you want to push the data into a staging table and then move data after cleaning. During next upload you don’t want the previous uploaded data but want to have it for reference. In this case, this renaming helps tons.
Sometime there are cases, where you want to change the schema like renaming a column like “Phone” to “Telephone” or “Cell” but don’t want to add another column or get into migration of data. This is a neat way to work around this.
sp_rename [ @objname = ] 'object_name' ,
[ @newname = ] 'new_name'
[ , [ @objtype = ] 'object_type' ]
More about this lesser known command can be got from Documentation.
Note: Use it with utmost care as this involves Schema change directly !!!
This entry was posted on Thursday, October 14th, 2010 at 08:30 and is filed under Uncategorized. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.