这是一个很难理解的问题,但是,我需要截断一个表,同时插入新的寄存器,但是在此过程中,网站访问者看不到网站内容没有任何内容,我该如何在SQL中像--single-transation在新的缓存出现之前有“缓存的缓存”之类的东西吗?
Use rename table to switch 2 tables.
RENAME TABLE, unlike ALTER TABLE, can rename multiple tables within a single statement:
the_table_next
(can be a long operation) RENAME TABLE the_table TO the_table_prev, the_table_next To the_table;
(very fast operation) 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.
Note :
with alter table rename
you need use 2 command ==> 2 different transaction (DDL instruction)
with rename table
=> single transaction
If you can truncate the table then it's OK to assume that there are no key restrictions on that table. If that is so I would:
In MySQL you can rename tables with:
ALTER TABLE table_name
RENAME TO new_table_name;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.