Home > Database > Mysql Tutorial > body text

MySQL 的Rename Table语句

WBOY
Release: 2016-06-07 17:00:42
Original
1311 people have browsed it

RENAME TABLE current_db.tbl_name TO other_db.tbl_name;当你执行 RENAME 时,你不能有任何锁定的表或活动的事务。你同样也必须

mysql 命令重命名表RENAME TABLE 句法

RENAME TABLE tbl_name TO new_tbl_name[, tbl_name2 TO
new_tbl_name2,...]
更名是以原子方式(atomically)执行,这就意味着,当更名正在运行时,其它的任何线程均不能该表。这使得以一个空表替换一个表成为可能。

CREATE TABLE new_table (...);
RENAME TABLE old_table TO backup_table, new_table TO old_table;
改名是从左到右执行的,这就意味着,,如果你希望交换两个表名,你不得不这样做:

RENAME TABLE old_table    TO backup_table,
             new_table    TO old_table,
             backup_table TO new_table;
只要两个数据库在同一个磁盘上,你也可以从一个数据库更名到另一个数据库:

RENAME TABLE current_db.tbl_name TO other_db.tbl_name;
当你执行 RENAME 时,你不能有任何锁定的表或活动的事务。你同样也必须有对原初表的 ALTER 和 DROP 权限,以及对新表的 CREATE 和 INSERT 权限。

如果在多表更名中,MySQL 遭遇到任何错误,它将对所有被更名的表进行倒退更名,将每件事物退回到最初状态。

RENAME TABLE 在 MySQL 3.23.23 中被加入。

linux

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!