mysql 自增列的创建

1.建表时就创建自增列:

create table test
(
 id int auto_increment primary key,
 name varchar(20) not null,
 password varchar(20) not null
);


insert into test values(null,'aa','aa');
insert into test values(null,'bb','bb');

 

注意:

      插入语句时,自增列的值为NULL。

 

2、创建表格后添加: alter table table1 add id int auto_increment primary key 自增字段,一定要设置为primary key.

你可能感兴趣的:(mysql)