

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Change the Auto Increment counter in MySQL?
In MySQL, auto increment counter starts from 0 by default, but if you want the auto increment to start from another number, use the below syntax.
ALTER TABLE yourTable auto_increment=yourIntegerNumber;
To understand the above syntax, let us first create a table. The query to create a table is as follows.
mysql> create table startAutoIncrement -> ( -> Counter int auto_increment , -> primary key(Counter) -> ); Query OK, 0 rows affected (0.90 sec)
Implement the above syntax to begin auto increment from 20. The query is as follows.
mysql> alter table startAutoIncrement auto_increment=20; Query OK, 0 rows affected (0.30 sec) Records: 0 Duplicates: 0 Warnings: 0
Insert some records in the table using insert command. The query is as follows.
mysql> insert into startAutoIncrement values(); Query OK, 1 row affected (0.20 sec) mysql> insert into startAutoIncrement values(); Query OK, 1 row affected (0.14 sec) mysql> insert into startAutoIncrement values(); Query OK, 1 row affected (0.18 sec)
Now you can check the table records from where auto increment started. We changed the auto increment to begin from 20 above.
The following is the query to display all records from the table using select statement.
mysql> select *from startAutoIncrement;
The following is the output.
+---------+ | Counter | +---------+ | 20 | | 21 | | 22 | +---------+ 3 rows in set (0.00 sec)
- Related Questions & Answers
- How to change auto increment number in MySQL?
- SELECT increment counter in MySQL?
- How to change auto increment number in the beginning in MySQL?
- CSS counter-increment property
- Passing NULL to MySQL for auto increment?
- Set custom Auto Increment with ZEROFILL in MySQL
- How to get the next auto-increment id in MySQL?
- MySQL query to set my auto increment column ( id ) to zero or reset the value of auto increment field?
- Changing the current count of an Auto Increment value in MySQL?
- How to make MySQL table primary key auto increment?
- Two columns as primary key with auto-increment in MySQL?
- How to set initial value and auto increment in MySQL?
- Amortized analysis for increment in counter in C++
- How to handle fragmentation of auto increment ID column in MySQL?
- Set the MySQL primary keys auto increment to be unlimited (or incredibly huge)?
Advertisements