- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to reset auto-incrementing column in MySQL?
To reset auto-incrementing column, use TRUNCATE TABLE command. After that, on insertion, it will reset the column.
Let us first create a table −
mysql> create table DemoTable1888 ( Id int NOT NULL AUTO_INCREMENT, PRIMARY KEY(Id) ); Query OK, 0 rows affected (0.00 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1888 values(); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1888 values(); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1888 values(); Query OK, 1 row affected (0.00 sec)
Display some records in the table using insert command −
mysql> select * from DemoTable1888;
This will produce the following output −
+----+ | Id | +----+ | 1 | | 2 | | 3 | +----+ 3 rows in set (0.00 sec)
Here is the query to reset auto-incrementing column −
mysql> truncate table DemoTable1888; Query OK, 0 rows affected (0.00 sec) mysql> select * from DemoTable1888; Empty set (0.00 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1888 values(); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1888 values(); Query OK, 1 row affected (0.00 sec)
Display some records in the table using insert command −
mysql> select * from DemoTable1888;
This will produce the following output −
+----+ | Id | +----+ | 1 | | 2 | +----+ 2 rows in set (0.00 sec)
- Related Articles
- How to work with auto incrementing column in MySQL?
- MySQL query to set my auto increment column ( id ) to zero or reset the value of auto increment field?
- How to handle fragmentation of auto increment ID column in MySQL?
- How to add auto-increment to column in MySQL database using PhpMyAdmin?
- How to create a table with auto-increment column in MySQL using JDBC?
- MySQL date column auto fill with current date?
- How to set the initial value of an auto-incremented column in MySQL using JDBC?
- Reset AUTO_INCREMENT in MySQL
- How to change auto increment number in MySQL?
- How to Auto Generate Database Diagram in MySQL?
- Set MySQL int column to auto increment by 1 beginning at 10000?
- How to reset or change the MySQL root password?
- Reset Primary Key in MySQL
- How to perform update in MySQL to disallow incrementing all the values above a specific value?
- Reset MySQL field to default value?

Advertisements