
The auto_increment is a default property that automatically increments the newly added recordby 1. The auto_increment can be changed from the beginning as well. The procedure for that isgiven below −
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中更改自动递增的起始数字?的详细内容,更多请关注创想鸟其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/120098.html
微信扫一扫
支付宝扫一扫