作者:傻傻的不敢看结5_749 | 来源:互联网 | 2023-06-25 20:57
1,删除原有主键:ALTERTABLE`table_name`DROP`id`;2,添加新主键字段:ALTERTABLE`table_name`ADD`id`MEDIUMI
1,删除原有主键:
ALTER TABLE `table_name` DROP `id`;
2,添加新主键字段:
ALTER TABLE `table_name` ADD `id` MEDIUMINT( 8 ) NOT NULL FIRST;
3,设置新主键:
ALTER TABLE `table_name` MODIFY COLUMN `id` MEDIUMINT( 8 ) NOT NULL AUTO_INCREMENT,ADD PRIMARY KEY(id);
4.导入数据
insert into `b` select * from `a`
例子:
ALTER TABLE `a` DROP `id`;
alter table `a` AUTO_INCREMENT=1000000;
ALTER TABLE `a` ADD `id` MEDIUMINT( 8 ) NOT NULL FIRST;
ALTER TABLE `a` MODIFY COLUMN `id` MEDIUMINT( 8 ) NOT NULL AUTO_INCREMENT,ADD PRIMARY KEY(id);
insert into `b` select * from `a`