Renaming a Table in SQL Server
To rename a table in SQL Server, you can use the sp_rename system stored procedure. This stored procedure allows you to change the name of an existing table, without having to drop and re-create the table.
To use the sp_rename stored procedure, you need to specify the current name of the table and the new name you want to give the table. For example, to rename a table named old_table_name to new_table_name, you can use the following syntax:
EXEC sp_rename 'old_table_name', 'new_table_name';
This will change the name of the table from old_table_name to new_table_name, without affecting the data in the table or the indexes and constraints associated with the table.
It is important to note that the sp_rename stored procedure only renames the table; it does not move the table to a new location or change the schema of the table. If you want to move the table to a different schema, you will need to use other SQL commands to do so.
In conclusion, the sp_rename stored procedure is a simple and efficient way to rename a table in SQL Server. This stored procedure allows you to easily change the name of an existing table without having to drop and re-create the table, which can save time and effort.
More from Stedman Solutions:
Steve and the team at Stedman Solutions are here for all your SQL Server needs.
Contact us today for your free 30 minute consultation..
We are ready to help!
Leave a Reply