在MySQL中如何改变自动递增的起始数?

2024年04月03日 建站教程

//创建DemoAuto表
mysql> CREATE table DemoAuto
-> (
-> id int auto_increment,
-> name varchar(100),
-> primary key(id)
-> );
Query OK, 0 rows affected (0.47 sec)

//修改DemoAuto表
mysql> alter table DemoAuto auto_increment = 100;
Query OK, 0 rows affected (0.24 sec)
Records: 0 Duplicates: 0 Warnings: 0

//将一些记录插入表中
mysql> INSERT into DemoAuto(name) values('John');
Query OK, 1 row affected (0.10 sec)
 
mysql> INSERT into DemoAuto(name) values('Smith');
Query OK, 1 row affected (0.13 sec)
 
mysql> INSERT into DemoAuto(name) values('Bob');
Query OK, 1 row affected (0.22 sec)

输出结果:

mysql> SELECT * from DemoAuto;

+-----+-------+
| id  | name  |
+-----+-------+
| 100 | John  |
| 101 | Smith |
| 102 | Bob   |
+-----+-------+
3 rows in set (0.00 sec)

本文链接:http://so.lmcjl.com/news/1015/

展开阅读全文