gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 07:35:21 24 4
gpt4 key购买 nike

我正在使用 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/

24 4 0