一、标识列
又称自增长列(auto_increment)
含义:可以不用手动的插入值,系统默认提供默认的序列值,从1开始,每次增加1;
1、创建表时设置标识列
create table tab_indetity(
    id int primary key auto_increment,
    name varchar(20)
)
2、show variables like '%auto_increment%'; 查看增长列配置
0
起始值默认为1,修改后也无法生效
步长修改:
set auto_increment_increment=3;
2、在修改表时增加标识列
alter table 表名 modify column 字段 字段类型 【约束】 auto_increment;
3、修改表时删除标识列(把auto_increment去掉即可)
alter table 表名 modify column 字段 字段类型 【约束】 ;
特点:
1、创建标识列的前提是该列必须是一个key
2、一个表只能有一个标识列
3、标识列的类型只能是数值型
4、可以通过“set auto_increment_increment=3;”设置步长,也可以通过手动插入值设置起始值(例如我在标识列插入值为10,那下一次自增长的值就为11)
 
posted on 2022-07-17 22:11  时光以北暮南城  阅读(51)  评论(0编辑  收藏  举报