
- 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
Truncate a MySQL table and then set a custom value to auto increment
Let us first create a table −
mysql> create table DemoTable825(Value int NOT NULL AUTO_INCREMENT PRIMARY KEY); Query OK, 0 rows affected (0.63 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable825 values(); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable825 values(); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable825 values(); Query OK, 1 row affected (0.11 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable825;
This will produce the following output −
+-------+ | Value | +-------+ | 1 | | 2 | | 3 | +-------+ 3 rows in set (0.00 sec)
Following is the query to truncate the table and then update auto_increment value −
mysql> truncate table DemoTable825; Query OK, 0 rows affected (0.58 sec)
Following is the query to change the auto_increment value −
mysql> alter table DemoTable825 auto_increment=2000; Query OK, 0 rows affected (0.16 sec) Records: 0 Duplicates: 0 Warnings: 0
Insert some records in the table using insert command −
mysql> insert into DemoTable825 values(); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable825 values(); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable825 values(); Query OK, 1 row affected (0.09 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable825;
This will produce the following output −
+-------+ | Value | +-------+ | 2000 | | 2001 | | 2002 | +-------+ 3 rows in set (0.00 sec)
- Related Articles
- Set custom Auto Increment with ZEROFILL in MySQL
- Set auto increment initial value for MySQL table using ALTER command
- How to set initial value and auto increment in MySQL?
- MySQL query to set my auto increment column ( id ) to zero or reset the value of auto increment field?
- How to make MySQL table primary key auto increment?
- How can I set my auto-increment value to begin from 1 in MySQL?
- How to create a table with auto-increment column in MySQL using JDBC?
- How to auto increment with 1 after deleting data from a MySQL table?
- How to set auto-increment to an existing column in a table using JDBC API?
- How to auto-increment value of tables to lower value in MySQL?
- Add a column to a MySQL table which is the result of concatenation of text and value from another auto increment column?
- Set MySQL int column to auto increment by 1 beginning at 10000?
- MongoDB query to increment a specific value using custom variable
- Passing NULL to MySQL for auto increment?
- What if I forgot to set Auto Increment? Can I set it later in MySQL?

Advertisements