Set MySQL int column to auto increment by 1 beginning at 10000?



Let us first create a table. Here, we have set UserId as AUTO_INCREMENT PRIMARY KEY −

mysql> create table DemoTable (    UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY ); Query OK, 0 rows affected (0.72 sec)

Following is the query to set int column to auto increment by 1 beginning at 10000 −

mysql> alter table DemoTable AUTO_INCREMENT=10000; Query OK, 0 rows affected (0.31 sec) Records: 0 Duplicates: 0 Warnings: 0

Insert records in the table using insert command −

mysql> insert into DemoTable values(); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values(); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values(); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values(); Query OK, 1 row affected (0.08 sec)

Display records from the table using select command −

mysql> select *from DemoTable;

This will produce the following output −

+--------+ | UserId | +--------+ | 10000 | | 10001 | | 10002 | | 10003 | +--------+ 4 rows in set (0.00 sec)
Updated on: 2019-07-30T22:30:25+05:30

606 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements