MS SQL Server Concepts and Programming Question:
Download Questions PDF

How to rename an existing table with the "sp_rename" stored procedure in MS SQL Server?

Answer:

If you have an existing table and you want to change the table name, you can use the "sp_rename ... 'OBJECT'" stored procedure. "sp_rename" allows you to change names of COLUMN, DATABASE, INDEX, USERDATATYPE, and OBJECT (including tables). The tutorial example below shows you how to rename a table:

sp_rename 'tip', 'faq', 'OBJECT'
GO
Caution: Changing any part of an object name could break
scripts and stored procedures.

SELECT name, type_desc, create_date FROM sys.tables
GO
name type_desc create_date
faq USER_TABLE 2007-05-19 23:05:43.700
tipBackup USER_TABLE 2007-05-19 23:25:23.357

You can also rename a table with on the Object Explorer window of SQL Server Management Studio. See tutorials on rename table columns.

Download MS SQL Server Interview Questions And Answers PDF

Previous QuestionNext Question
How to change the data type of an existing column with "ALTER TABLE" statements in MS SQL Server?How To Drop an Existing Table with "DROP TABLE" Statements in MS SQL Server?