T-SQL script to rename table

Renaming a table is a simple task, however one thing most people miss is to find all table dependencies and replace the table in stored procedures/functions/views using that particular table. A T-SQL script to rename table is shown below

EXEC sp_rename 'Person.Address', 'Addresses';

The above query renames Person.Address to Addresses table. Refer to https://www.sqlservergeeks.com/find-dependencies-of-a-table-in-sql-server/  to find table dependencies and rename the table there too.

Any object can also be renamed using GUI. Navigate to the object to rename and click F2 to rename it.

t sql script to rename table

 

Like us on FaceBook Join the fastest growing SQL Server group on FaceBook

Data Platform Virtual Summit 2020

Subscribe to SQLServerGeeks YouTube channel. If you want more learning content in your inbox, subscribe to SQLServerGeeks Bulletin.

SQLServerGeeks YouTube | SQLServerGeeks Bulletin | SQLServerGeeks Twitter

Leave a Reply

Your email address will not be published. Required fields are marked *