如何使用 SQL 查询更改表名?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/886786/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 02:09:06  来源:igfitidea点击:

How to change a table name using an SQL query?

sqlsql-serversql-server-2005

提问by David M

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.

我使用了以下语法,但在 SQL Server 2005 中找不到 rename 关键字。

Alter table Stu_Table rename to Stu_Table_10

回答by David M

Use sp_rename:

使用 sp_rename:

EXEC sp_rename 'Stu_Table', 'Stu_Table_10'

You can find documentation on this procedure on MSDN.

您可以在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'

回答by djairo

In MySQL:-

MySQL:-

RENAME TABLE `Stu Table` TO `Stu Table_10`

回答by Ravindra K.

Please use this on SQL Server 2005:

请在 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.

但您的表名将被更改。

回答by Kamran

In Postgress SQL:

在 Postgress SQL 中:

Alter table student rename to student_details;

回答by Devendra Singraul

In MySQL :

在 MySQL 中:

RENAME TABLE template_functionTO business_function;

RENAME TABLE template_functionTO business_function;

回答by Ashutosh K Singh

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

ALTER TABLE table_name 重命名为 new_table_name; 也适用于 MySQL。

Screen shot of this Query run in MySQL server

此查询在 MySQL 服务器中运行的屏幕截图

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

可替换地:RENAME TABLE table_nameTO new_table_name; 此查询在 MySQL 服务器中运行的屏幕截图

回答by Avinash

Syntex for latest MySQL versions has been changed.

最新 MySQL 版本的语法已更改。

So try RENAME command without SINGLE QUOTESin table names.

所以尝试在表名中没有单引号的RENAME 命令。

RENAME TABLE old_name_of_table TO new_name_of_table;

RENAME TABLE old_name_of_table TO new_name_of_table;

回答by Hazeena

RENAME TABLE old_table_name TO new_table_name;

回答by Sai Gopi N

execute this command

执行这个命令

sp_rename 'Employee','EData'

回答by pradip kor

rename table name :

重命名表名:

RENAME TABLE old_tableName TO new_tableName;

for example:

例如:

RENAME TABLE company_name TO company_master;