- 论坛徽章:
- 0
|
进入数据库之后,use数据库,set sql_mode='no_auto_value_on_zero',创建数据表,第一行手动插入id值为0,下面直接插入值,id会自动从1开始,这样也能达到你要求的效果,只是不知道还有没有更好的办法,步骤如下
mysql> use nihao;
Database changed
mysql> set sql_mode='no_auto_value_on_zero';
Query OK, 0 rows affected (0.00 sec)
mysql> create table test1 (id int primary key auto_increment,name varchar(12)) engine=innodb;
Query OK, 0 rows affected (0.04 sec)
mysql> insert into test1 values(0,'li');
Query OK, 1 row affected (0.02 sec)
mysql> select * from test1;
+----+------+
| id | name |
+----+------+
| 0 | li |
+----+------+
1 row in set (0.00 sec)
mysql> insert into test1 (name ) values('yang'),('fan');
Query OK, 2 rows affected (0.02 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> select * from test1;
+----+------+
| id | name |
+----+------+
| 0 | li |
| 1 | yang |
| 2 | fan |
+----+------+
3 rows in set (0.00 sec)
回复 1# chenxiaopang
|
|