How to change a table name using an SQL query?

SqlSql ServerSql Server-2005

Sql Problem Overview


How can I in change the table name using a query statement?

I used the following syntax but I couldn't find the rename keyword in SQL server 2005.

Alter table Stu_Table rename to Stu_Table_10

Sql Solutions


Solution 1 - Sql

Use sp_rename:

EXEC sp_rename 'Stu_Table', 'Stu_Table_10'

You can find documentation on this procedure on MSDN.

If you need to include a schema name, this can only be included in the first parameter (that is, this cannot be used to move a table from one schema to another). So, for example, this is valid:

EXEC sp_rename 'myschema.Stu_Table', 'Stu_Table_10'

Solution 2 - Sql

In MySQL :-

RENAME TABLE `Stu Table` TO `Stu Table_10`

Solution 3 - Sql

In Postgress SQL:

Alter table student rename to student_details;

Solution 4 - Sql

Please use this on SQL Server 2005:

sp_rename old_table_name , new_table_name

it will give you:

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

but your table name will be changed.

Solution 5 - Sql

In MySQL :

RENAME TABLE template_function TO business_function;

Solution 6 - Sql

ALTER TABLE table_name RENAME TO new_table_name; works in MySQL as well.

Screen shot of this Query run in MySQL server

Alternatively: RENAME TABLE table_name TO new_table_name; Screen shot of this Query run in MySQL server

Solution 7 - Sql

Syntex for latest MySQL versions has been changed.

So try RENAME command without SINGLE QUOTES in table names.

RENAME TABLE old_name_of_table TO new_name_of_table;

Solution 8 - Sql

RENAME TABLE old_table_name TO new_table_name;

Solution 9 - Sql

execute this command

sp_rename 'Employee','EData'

Solution 10 - Sql

rename table name :

RENAME TABLE old_tableName TO new_tableName;

for example:

RENAME TABLE company_name TO company_master;

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionsivaView Question on Stackoverflow
Solution 1 - SqlDavid MView Answer on Stackoverflow
Solution 2 - SqldjairoView Answer on Stackoverflow
Solution 3 - SqlKamranView Answer on Stackoverflow
Solution 4 - SqlRavindra K.View Answer on Stackoverflow
Solution 5 - SqlDevendra SingraulView Answer on Stackoverflow
Solution 6 - SqlAshutosh K SinghView Answer on Stackoverflow
Solution 7 - SqlAvinashView Answer on Stackoverflow
Solution 8 - SqlHazeenaView Answer on Stackoverflow
Solution 9 - Sqlsaigopi.meView Answer on Stackoverflow
Solution 10 - Sqlpradip korView Answer on Stackoverflow