How To Rename The Table Name In SQL Server

Recently, a new MNC took over my current organization. My manager asked me to rename our database’s existing tables based on the latest company name. As a developer, I analyzed the requirements and identified the best approaches to changing the table names in the SQL server.

Approach-1 Using the sp_rename Stored Procedure

You can rename the table using the sp_rename stored procedure.

Syntax

EXEC sp_rename 'old table name', 'new table name'

Example

We can execute the below query to rename from the Orders table to OrderLatest.

EXEC sp_rename 'Orders', 'OrderLatest'
how to rename sql table name in sql server

The table name has been changed successfully, as shown in the screenshot below.

Check out How to get table size in SQL Server

change table name sql server

If you are required to rename multiple tables at once, you can run the above query multiple times, as shown below.

EXEC sp_rename 'Orders', 'OrderLatest'
EXEC sp_rename 'Products', 'ProductsLatest'
EXEC sp_rename 'Vehicle', 'VehicleLatest'

Approach-2 Using the SQL Server Management Studio

Follow the below steps.

1. On the object explorer, right-click the table name and select the Rename option, as shown in the screenshot.

    how to change table name in sql server using query

    2. Enter the new name and press the Enter key from your keyboard.

    rename table name in sql server using query

    The name changed successfully, as shown in the screenshot below.

    Check out How To Check If Table Exists In SQL Server

    sql change table name sql server

    Or,

    You can do this by clicking on the table name, entering the new table name, and pressing the enter key, as shown below.

    query to rename table name in sql server

    Conclusion

    Renaming tables in SQL Server looks quite easy, but you need to be a little careful while renaming the table as it may break the existing functionality.

    You may also like following the articles below.