mysql rename table Syntax

        原先想坚持看mysql手册,实在看不下去,犯困。所以嘛,用到的时候就一定去看看。手册能解决很多需要反复试的东西啦。我觉得速度还是很重要的。

         今天用到rename table,所以看下这一节。

         MySQL 5.1 Manual     12.1.33. RENAME TABLE Syntax

         12.1.33. RENAME TABLE Syntax

 
 

This statement renames one or more tables.

可以同时rename多个table。

The rename operation is done atomically, which means that  no other session can access any of the tables while the rename is running. For example, if you have an existing table old_table, you can create another table new_table that has the same structure but is empty, and then replace the existing table with the empty one as follows (assuming that backup_table does not already exist):

 
   
 
  

If the statement renames more than one table, renaming operations are done from left to right. If you want to swap two table names, you can do so like this (assuming that tmp_table does not already exist):

多个table,rename为从左至右的顺序。

 
  

As long as  two databases are on the same file system, you can use  RENAME TABLE  to move a table from one database to another:

可以改到另一个database,前提是在同一个文件系统上,这个一般都会满足吧。

 
  

If there are any triggers associated with a table which is moved to  a different database  using  RENAME TABLE , then the statement   fails with the error Trigger in wrong schema.

有trigger,还要改database,那就会报错了,Trigger in wrong schema。

RENAME TABLE also works for views, as long as you  do not try to rename a view into a different database.

rename table 可以改变view的名字,但是不能rename到另一个数据库。

Any privileges granted specifically for the renamed table or view are not migrated to the new name. They must be changed manually.

对于table或view上特别指定的权限就不能自动转移啦,只能手动修改了011.gif

When you execute RENAME, you cannot have any locked tables or active transactions. You must also have the  ALTER  and  DROP  privileges on the original table, and the  CREATE  and  INSERT  privileges on the new table.

rename不能被锁住表,或者有active transactions。旧表你要有ALTER and DROP权限,然后需要CREATE and INSERT来对新表进行操作

If MySQL encounters any errors in a multiple-table rename, it does a reverse rename for all renamed tables to  return everything  to its original state.

多个表rename时出错的话,所有的表都会回到原先状态。

You  cannot use RENAME  to rename a TEMPORARY  table. However, you can use  ALTER TABLE  instead:

 
   
 
  

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/23650854/viewspace-695239/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/23650854/viewspace-695239/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值