表里面有十几条记录了 表名 temp 列名id 要求是mysql的写法 添加数据进去id列自动增长
第1个回答 2013-05-04
alter table temp change id id int primary key auto_increment; ---------------------------id不是主键的情况下,
如果id已经是主键,alter table temp change id id int auto_increment;
如果id已经是主键,alter table temp change id id int auto_increment;
第2个回答 2018-10-31
alter table temp
add id int primary key auto_increment first;
新建的字段,肯定是没有设置过主键的。add语句就可以解决。既然是id,所以建议放在第一列,因此最后可加first。
add id int primary key auto_increment first;
新建的字段,肯定是没有设置过主键的。add语句就可以解决。既然是id,所以建议放在第一列,因此最后可加first。
第3个回答 推荐于2016-08-29
办法是,创建一个带有id的新表,id是自动增长的,temp1,其余字段和temp表相同,
将temp表数据插入到temp1.
insert into temp1 select * from temp追问
将temp表数据插入到temp1.
insert into temp1 select * from temp追问
假设我原来表有 字段 name age sex 这是三个字段 三个都是 字符型 那我创建新表的代码是怎么样的
追答create table temp1
(
id int(10) unsigned NOT NULL AUTO_INCREMENT,
name varchar(20) not null,
sex char(2) not null,
age int not null,
primary key(id)
);