
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
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 Articles
- How to change auto increment number in MySQL?
- SELECT increment counter in MySQL?
- How to change auto increment number in the beginning in MySQL?
- Set custom Auto Increment with ZEROFILL in MySQL
- CSS counter-increment property
- Passing NULL to MySQL for auto increment?
- 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?
- Two columns as primary key with auto-increment in MySQL?
- How to set initial value and auto increment in MySQL?
- How to make MySQL table primary key auto increment?
- Amortized analysis for increment in counter in C++
- How to handle fragmentation of auto increment ID column in MySQL?
- How to auto-increment value of tables to lower value in MySQL?

Advertisements