rename table in sql server

How To Rename Table in SQL Server

Sometimes you may need to change table name or alter table name in SQL Server. In this article, we will look at how to rename table in SQL Server.


How To Rename Table in SQL Server

SQL Server offers many stored procedures to help you get work done quickly. You can easily rename table in SQL Server using sp_rename stored procedure.

Here is the syntax of sp_rename stored procedures:

EXEC sp_rename 'old_table_name', 'new_table_name'

Also read : Insert into Table from Another Table in SQL Server

Let us say you want to rename sales table to new_sales table.

EXEC sp_rename 'sales', 'new_sales'

On execution of above command, you will see the following message,

Caution: Changing any part of an object name could break scripts and stored procedures.

As you can see, renaming a table will cause the stored procedures and scripts that reference it to stop working. So, after you rename table in SQL Server, you need to update the scripts & stored procedures that refer to your table, to refer to its new table name.

Also Read : How to Update Multiple Columns in SQL Server

Leave a Reply

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