mysql增加自增主键

mysql没有主键时,处于只读模式,对已有数据无法修改,此时可以增加自增主键解决。

ALTER TABLE test ADD new_field_id int(5)  not null auto_increment ,ADD primary key (new_field_id);

原有数据已有主键,想增加自增字段为主键:

alter table face_user_info add primary key (iid int auto_increment);

ALTER TABLE face_user_info ADD new_field_id int(5) not null auto_increment ,ADD primary key (new_field_id);

update face_user_info set user_type=3 where new_field_id>24;
delete from face_user_info where new_field_id>36;

//倍增数据
insert into face_user_info select * from face_user_info

你可能感兴趣的:(mysql)