Pages

Wednesday, May 21, 2014

How to Rename Tables in SQL Server

You can rename a table in SQL Server 2014 by using SQL Server Management Studio or Transact-SQL.


  • Using SQL Server Management Studio

1. To rename a table,  In Object Explorer, right-click the table you want to rename and choose Design from the   shortcut menu.


2. From the View menu, choose Properties.

3. In the field for the Name value in the Properties window, type a new name for the table.

4. To cancel this action, press the ESC key before leaving this field.


5. From the File menu choose Save table name.
  • Using Transact-SQL

1. To rename a table In Object Explorer, connect to an instance of Database Engine.


2. On the Standard bar, click New Query.

3. The following example renames the "login" table to "Users" in the  schema. Copy and paste the following example into the query window and click Execute.
                         
                           EXEC sp_rename 'login', 'Users';
(Note: make sure that you have selected correct database to which table to be rename is belong)

Limitations and Restrictions

Renaming a table will not automatically rename references to that table. You must manually modify any objects that reference the renamed table. For example, if you rename a table and that table is referenced in a trigger, you must modify the trigger to reflect the new table name. 

    Friends, If you like this post, please share with your friends on Facebook and Google+ and recommend us on Google using the g+1 button on the top right hand corner.

No comments:

Post a Comment