如何在 MySQL 开始时更改自动增量号?
auto_increment是一个默认属性,它会自动将新添加的记录增加1。auto_increment也可以从头开始更改。其程序如下-
首先,创建一个表。
mysql> CREATE table DemoAuto -> ( -> id int auto_increment, -> name varchar(100), -> primary key(id) -> );
之后使用altertable命令更改auto_incremnt的起始编号,默认从1开始。起始值更改为100。
mysql> alter table DemoAuto auto_increment = 100; Records: 0 Duplicates: 0 Warnings: 0
然后将一些记录插入到table.This给出如下-
mysql> INSERT into DemoAuto(name) values('John'); mysql> INSERT into DemoAuto(name) values('Smith'); mysql> INSERT into DemoAuto(name) values('Bob');
select语句用于获取表值作为输出。这在下面给出-
mysql> SELECT * from DemoAuto;
以下是获得的输出-
+-----+-------+ | id | name | +-----+-------+ | 100 | John | | 101 | Smith | | 102 | Bob | +-----+-------+ 3 rows in set (0.00 sec)
在上面的输出中,记录id从100开始。