first, a table is created.
mysql> create table demoauto-> (-> id int auto_increment,-> name varchar(100),-> primary key(id)-> );query ok, 0 rows affected (0.47 sec)
after that the alter table command is used to change the starting number of auto_incremntwhich starts from 1 by default. the starting value is changed to 100.
mysql> alter table demoauto auto_increment = 100;query ok, 0 rows affected (0.24 sec)records: 0 duplicates: 0 warnings: 0
then some records are inserted into the table.this is given as follows −
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)
the select statement is used to obtain the table values as output. this is given below −
mysql> select * from demoauto;
the following is the output obtained −
+-----+-------+| id | name |+-----+-------+| 100 | john || 101 | smith || 102 | bob |+-----+-------+3 rows in set (0.00 sec)
in the above output, the record id starts from 100.
以上就是如何在mysql中更改自动递增的起始数字?的详细内容。
