赶知识网

mysql复制表的命令

2020-08-11 / 1479次点击 php/mysql/apache

mysql复制表的命令

select max(id) from tb1;   -- 记录下当前最大的自增id为 xxxx

create table tb2 LIKE tb1;   -- 复制表结构
 
alter table tb2 modify column id  bigint unsigned not null auto_increment ;   -- 修改新表为bigint unsigned类型,能存 18446744073709551615 行数据。
alter table tb2 auto_increment=xxxx+1;  -- 改大新表的自增主键起始值
 
rename table tb1 to tb_archive , tb2 to tb1;  -- 切换表名
有用 0 没用 0

Top10

沪ICP备09053415号 © 赶知识网