mysql - 'alter table rename' 和 'rename table' 有什么区别?

标签 mysql alter-table table-rename

我正在使用 MySQL。这是一个例子,我想将表 A 重命名为 B,那么以下语句之间有什么区别:

alter table A rename to B;

还有这个:

rename table A to B;

有谁能详细比较一下吗?它是否因不同的引擎而异?

最佳答案

根据 ALTER TABLE Syntax 记录:

For ALTER TABLE <em>tbl_name</em> RENAME TO <em>new_tbl_name</em> without any other options, MySQL simply renames any files that correspond to the table tbl_name without making a copy. (You can also use the RENAME TABLE statement to rename tables. See Section 13.1.32, “RENAME TABLE Syntax”.) Any privileges granted specifically for the renamed table are not migrated to the new name. They must be changed manually.

根据 RENAME TABLE Syntax 记录:

RENAME TABLE, unlike ALTER TABLE, can rename multiple tables within a single statement:

RENAME TABLE old_table1 TO new_table1,
             old_table2 TO new_table2,
             old_table3 TO new_table3;

[ <strong><em>deletia</em></strong> ]

RENAME TABLE does not work for TEMPORARY tables. However, you can use ALTER TABLE to rename temporary tables.

RENAME TABLE works for views, except that views cannot be renamed into a different database.

没有其他区别。

关于mysql - 'alter table rename' 和 'rename table' 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18988797/

相关文章:

oracle - 在 oracle 中缩小一列

sql - Oracle - 删除表约束而不删除表

oracle - 重命名 Oracle 表或 View

php - 提交 php.mysql 表单后出现访问被拒绝错误

php - 准备好的语句在查询时失败

mysql - 在 MySQL 中同时更改多个字段类型

sql - 更改 Oracle 表名

MySQL 导出到 Outfile 问题

php - 通过电子邮件验证链接

sql - 修改表以修改列的默认值