mysql自增主键

MariaDB [test]> create table test1(id int primary key auto_increment,name varchar(20))auto_increment=1;               #id为自增主键,默认从1开始递增
Query OK, 0 rows affected (0.07 sec)

MariaDB [test]> insert into test1 values(null,'linux');      #注意,需要null,否则列数不对应mysql会报错
Query OK, 1 row affected (0.01 sec)

MariaDB [test]> insert into test1 values(null,'linux2');
Query OK, 1 row affected (0.00 sec)

MariaDB [test]> insert into test1 values(null,'linux3');
Query OK, 1 row affected (0.00 sec)

MariaDB [test]> select * from test1;
+----+--------+
| id | name   |
+----+--------+
|  1 | linux  |
|  2 | linux2 |
|  3 | linux3 |
+----+--------+
3 rows in set (0.05 sec)

MariaDB [test]> 

posted on 2017-10-25 18:06  标配的小号  阅读(157)  评论(0编辑  收藏  举报

导航