MySQL自增列之起始与步长

MySQL自增列之起始与步长

1. 自增列——起始:auto_increment --默认初始值为1,默认步长为1
代码演示:

--创建user表:
create table user (
ID int(4)primary key auto_increment,
name varchar(6) not null ,
age int (4) not null);

--插入数据16条  运行了4次
insert into user(name,age) value ('haha',16);
insert into user(name,age) value ('coco',15);
insert into user(name,age) value ('momo',19);
insert into user(name,age) value ('xixi',20);

运行:ID 自增:
MySQL自增列之起始与步长_第1张图片
删除数据:

-- 删除表中数据
DELETE FROM `user`;
-- 再加一条数据
insert into user(name,age) value ('gogo',21);

自定义初始值:alter table 表名 auto_increment;

-- alter table user auto_increment=1;
-- insert into user(name,age) value ('gogo',21);
-- alt

你可能感兴趣的:(mysql)