
- 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
MySQL query to set my auto increment column ( id ) to zero or reset the value of auto increment field?
Use ALTER table to set the auto_increment column to 0 or reset with another value
ALTER TABLE yourTableName AUTO_INCREMENT=0;
The above syntax will begin from 1.
Let us first create a table −
mysql> create table DemoTable698 ( ClientId int NOT NULL AUTO_INCREMENT PRIMARY KEY ) auto_increment=109; Query OK, 0 rows affected (0.88 sec)
Here is the query to reset the auto_increment value to 0 −
mysql> alter table DemoTable698 AUTO_INCREMENT=0; Query OK, 0 rows affected (0.21 sec) Records: 0 Duplicates: 0 Warnings: 0
Insert some records in the table using insert command. Here, we haven’t inserted anything since we want to display auto increment value after setting it from beginning again −
mysql> insert into DemoTable698 values(); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable698 values(); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable698 values(); Query OK, 1 row affected (0.12 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable698;
This will produce the following output -
+----------+ | ClientId | +----------+ | 1 | | 2 | | 3 | +----------+ 3 rows in set (0.00 sec)
- Related Articles
- How to handle fragmentation of auto increment ID column in MySQL?
- How can I set my auto-increment value to begin from 1 in MySQL?
- How to set initial value and auto increment in MySQL?
- How to get the next auto-increment id in MySQL?
- Set MySQL int column to auto increment by 1 beginning at 10000?
- Set the MySQL primary keys auto increment to be unlimited (or incredibly huge)?
- Set custom Auto Increment with ZEROFILL in MySQL
- How to auto-increment value of tables to lower value in MySQL?
- Set auto increment initial value for MySQL table using ALTER command
- Passing NULL to MySQL for auto increment?
- Truncate a MySQL table and then set a custom value to auto increment
- Auto increment in MongoDB to store sequence of Unique User ID?
- How to add auto-increment to column in MySQL database using PhpMyAdmin?
- Display auto increment user id sequence number to begin from 001 in MySQL?
- How to change auto increment number in MySQL?

Advertisements