来源: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 ;
第三步:
重复插入:
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');
第四步:
插入并查询结果:
1 insert into category values(null,'nba');
产生变化了,中间断层了,
第五步:
重新排序:并查询:
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 ;