mysql 的表已经存在,但是我现在想添加一列 自动增长列

alter table temp change id id int primary key auto_increment; ---id不是主键的情况下,如果id已经是主键,alter table temp change id id int auto_increment;
mysql 的表已经存在,但是我现在想添加一列 自动增长列
办法是,创建一个带有id的新表,id是自动增长的,temp1,其余字段和temp表相同,
将temp表数据插入到temp1.

insert into temp1 select * from temp2013-05-04
alter table temp change id id int primary key auto_increment; ---------------------------id不是主键的情况下,

如果id已经是主键,alter table temp change id id int auto_increment;2013-05-04
alter table temp
add id int primary key auto_increment first;
新建的字段,肯定是没有设置过主键的。add语句就可以解决。既然是id,所以建议放在第一列,因此最后可加first。2018-10-31
mengvlog 阅读 6 次 更新于 2025-07-20 03:21:08 我来答关注问题0
檬味博客在线解答立即免费咨询

mySQL相关话题

Copyright © 2023 WWW.MENGVLOG.COM - 檬味博客
返回顶部