mysql - 我需要截断一个表然后插入新的寄存器,但用户看不到这个

标签 mysql sql insert truncate

这是一个很难理解的问题,但是,有一个表需要截断,同时插入新的寄存器,但是在此过程中,网站访问者看不到网站内容上没有任何内容,我该怎么做在像 --single-transation 这样的 SQL 中,在新的到来之前有类似“缓存寄存器”的东西?

最佳答案

使用rename table切换 2 个表。

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

  • 准备新表the_table_next(可能是一个很长的操作)
  • RENAME TABLE the_table TO the_table_prev, the_table_next To the_table; (非常快的操作)
  • 删除/截断表the_table_prev

When you execute RENAME TABLE, you cannot have any locked tables or active transactions. With that condition satisfied, the rename operation is done atomically; no other session can access any of the tables while the rename is in progress.

If any errors occur during a RENAME TABLE, the statement fails and no changes are made.

注意:

使用alter table rename,您需要使用2个命令==> 2个不同的事务(DDL指令)

带有重命名表 => 单个事务

关于mysql - 我需要截断一个表然后插入新的寄存器,但用户看不到这个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47479122/

相关文章:

Mysql实现及多字段查询效率

mysql - 为什么auto_increment id不一一增加,怎么设置呢?

sql - 查询字符长度的WHERE条件?

sql - 如何在oracle中单独更新年份字段?

mysql - 如何更新 JOIN 上的 SQL

sql - MySQL 将当前数据库与备份 SQL 文件合并

MySQL 在计数和分组时连接表

MYSQL将一个表中的数据插入到另一个表中

sql-server - 向sql server 2008表中插入数据

hadoop - 热点使用hive插入Cassandra