Reputation:
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
Upvotes: 131
Views: 442345
Reputation: 72870
Use sp_rename:
EXEC sp_rename 'myschema.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:
Upvotes: 243
Reputation: 69
SQL Server table name can be changed in two ways
Execute the below query, by using the system stored procedure sp_rename
EXEC sp_rename 'dbo.old_table_name','new_table_name'
;
Open SSMS and expand the database folder. Right-click on a table and click Rename. Enter a new name by over writing on existing name and then Go to the file menu and click Save.
Upvotes: 0
Reputation: 295
ALTER TABLE table_name RENAME TO new_table_name; works in MySQL as well.
Alternatively:
RENAME TABLE table_name
TO new_table_name
;
Upvotes: 3
Reputation: 951
In MySQL :
RENAME TABLE template_function
TO business_function
;
Upvotes: 6
Reputation: 469
rename table name :
RENAME TABLE old_tableName TO new_tableName;
for example:
RENAME TABLE company_name TO company_master;
Upvotes: -1
Reputation: 2191
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;
Upvotes: 2
Reputation: 171
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.
Upvotes: 17