How to change table name using SQL query?

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

I used the following syntax but could not find the rename keyword in SQL Server 2005.

Alter table Stu_Table rename to Stu_Table_10 
+99
sql sql-server sql-server-2005
May 20 '09 at 8:19
source share
9 answers

Use sp_rename:

 EXEC sp_rename 'Stu_Table', 'Stu_Table_10' 

You can find the documentation for this procedure on MSDN .

If you need to include a schema name, this can only be included in the first parameter (that is, it 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' 
+192
May 20 '09 at 8:21
source share

In MySQL : -

 RENAME TABLE `Stu Table` TO `Stu Table_10` 
+61
May 20 '09 at 8:21
source share

Please use this on SQL Server 2005:

 sp_rename old_table_name , new_table_name 

he will give you:

Warning: changing any part of the object name can lead to breakdown of scripts and stored procedures.

but the name of your table will be changed.

+14
Oct. 29 '10 at 10:44
source share

In Postgress SQL:

 Alter table student rename to student_details; 
+9
Aug 02 '17 at 6:11
source share

In MySQL:

Rename the template_function table TO business_function ;

+2
05 Oct '18 at 11:10
source share
 RENAME TABLE old_table_name TO new_table_name; 
0
Jun 07 '13 at 9:20
source share

The syntax for the latest versions of MySQL has been changed.

So, try to run the RENAME command without SINGLE QUOTES in the table names.

RENAME TABLE old_name_of_table TO new_name_of_table;

0
Mar 15 '17 at 1:46 on
source share

ALTER TABLE table_name RENAME TO new_table_name; also works in MySQL.

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

0
Dec 10 '18 at 21:51
source share

execute this command

 sp_rename 'Employee','EData' 
-one
Sep 13 '17 at 6:28
source share



All Articles