更改MySQL中Auto Increment值的当前计数?
您可以使用ALTER命令更改MySQL中auto_increment的当前计数。
语法如下-
ALTER TABLE yourTableName AUTO_INCREMENT = IntegerValue;
为了理解上述语法,让我们创建一个表。创建表的查询如下-
mysql> create table changeCurrentAutoIncrementValue −> ( −> CurrentCount int auto_increment, −> PRIMARY KEY(CurrentCount) −> );
使用select语句在表中插入记录。默认情况下,auto_increment从1开始,以1为增量。插入记录的查询如下-
mysql> insert into changeCurrentAutoIncrementValue values(); mysql> insert into changeCurrentAutoIncrementValue values(); mysql> insert into changeCurrentAutoIncrementValue values(); mysql> insert into changeCurrentAutoIncrementValue values(); Display all records to check from where the value starts. The query is as follows: mysql> select *from changeCurrentAutoIncrementValue;
以下是输出:
+--------------+ | CurrentCount | +--------------+ | 1 | | 2 | | 3 | | 4 | +--------------+ 4 rows in set (0.00 sec)
查看上面的示例输出,auto_increment从1开始,并且通过将前一个数字加1生成下一个数字。
这是更改当前auto_increment值的查询。查询如下-
mysql> alter table changeCurrentAutoIncrementValue auto_increment = 300; Records: 0 Duplicates: 0 Warnings: 0
看上面的查询。我们更改了auto_increment值。现在从300开始。新值将在上述值之后添加,即在4之后。
现在让我们再次在表中插入记录。查询如下-
mysql> insert into changeCurrentAutoIncrementValue values(); mysql> insert into changeCurrentAutoIncrementValue values(); mysql> insert into changeCurrentAutoIncrementValue values();
显示表中的记录以进行检查。查询如下-
mysql> select *from changeCurrentAutoIncrementValue;
以下是输出-
+--------------+ | CurrentCount | +--------------+ | 1 | | 2 | | 3 | | 4 | | 300 | | 301 | | 302 | +--------------+ 7 rows in set (0.00 sec)
查看上面的示例输出,更改auto_increment值后,该值从300开始
热门推荐
6 保研的祝福语简短
10 年轻20岁祝福语简短
11 朋友结婚祝福语信息简短
12 女孩婚礼贺卡祝福语简短
13 30段点歌简短祝福语
14 虎年春节祝福语图文简短
15 写给后妈祝福语大全简短
16 简短回复生日祝福语
17 校长送毕业祝福语简短
18 毕业立体贺卡祝福语简短