How to rename a table in SQL Server?

Switch picture Switch · Mar 17, 2011 · Viewed 488.8k times · Source

The SQL query that I have used is :

ALTER TABLE oldtable RENAME TO newtable;

But, it gives me an error.

Server: Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'TO'.

Answer

Jeff Hornby picture Jeff Hornby · Mar 17, 2011

To rename a table in SQL Server, use the sp_rename command:

exec sp_rename 'schema.old_table_name', 'new_table_name'