mysql 创建主键,修改主键



//添加一个字段pid并且设置为主键(auto_increment)自增(auto_increment),不可为null,类型为int unsigned
alter table table1 add pid int unsigned not null auto_increment primary key;


//可以将一个主键修改为0
update table1 set pid=0 where pid=6;

假设id为主键,id可以保证字段数据唯一性,但是一张表只有一个主键。
主键的值:修改成的0,可以存在,就是排个序。
新添加的0,不允许存在,要根据行号改变。
本身存在的0,不允许存在,要从1开始递增变化。
Insert 进去 id = 0的数据,数据会从实际的行数开始增加

insert table1 (transactor,name_new,pid) values("xiaohong","hahha",0);

参考:

https://www.cnblogs.com/sun-yanglu/p/9581701.html
https://www.jianshu.com/p/e9338da60a61

猜你喜欢

转载自www.cnblogs.com/sea-stream/p/11300539.html