Rename tables, columns, and objects in SQL

I started the New Year renaming some tables and columns to match a new schema. I forgot about a great stored procedure, so wrote this blog article to help me remember:

Rename any object (table, stored procedure, etc.):

EXEC sp_rename '[table_name]','[new_table_name]'

The object_type can be anything from this list: COLUMN, DATABASE, INDEX, OBJECT, STATISTICS, USERDATATYPE

So, to rename a column:

EXEC sp_rename '[table_name].[column_name]' , '[new_column_name]', 'COLUMN'

And to rename an index:

EXEC sp_rename '[table_name].[column_name].[index_name]' , '[new_index_name]', 'INDEX'

Leave a Reply