mysql 主键列_mysql----id主键列乱了之后,重新排序

来源:https://blog.csdn.net/weixin_42321963/article/details/82751622?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.channel_param&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.channel_param

实例如下:

第一步:

创建表如下:

1 create table category(

2 cid int(3)unsigned auto_increment primary key,

3 cname varchar(20) unique

4 );

第二步:

插入数据,并查询:

1 insert into category values(null,'衣服');

2 insert into category values(null,'皮包');

3 insert into category values(null,'手表');

4 insert into category values(null,'lala');

5

6 select * from category order by cid ;

b5804e1c9724eee5e9d2a2d730071bdf.png

第三步:

重复插入:

1 insert into category values(null,'衣服');

2 insert into category values(null,'皮包');

3 insert into category values(null,'手表');

4 insert into category values(null,'lala');

e02b6550ee2102442ab8b7496a044f0a.png

第四步:

插入并查询结果:

1 insert into category values(null,'nba');

4885b3a48709447d73197cd3a7141cd8.png

产生变化了,中间断层了,

第五步:

重新排序:并查询:

1 alter table category drop cid;

2 alter table category add cid int(3) not null first;

3 alter table category modify column cid int( 3 ) not null auto_increment,add primary key(cid);

4 select * from category order by cid ;

8fdb891097c05d642df166bb0b5b24da.png

标签:category,insert,cid,into,id,----,values,null,主键

来源: https://www.cnblogs.com/duolamengxiong/p/13671469.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值