

- 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
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 Questions & Answers
- Set custom Auto Increment with ZEROFILL in MySQL
- How to set initial value and auto increment in MySQL?
- Set auto increment initial value for MySQL table using ALTER command
- 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 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 can I set my auto-increment value to begin from 1 in MySQL?
- 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?
- MongoDB query to increment a specific value using custom variable
- Passing NULL to MySQL for auto increment?
- Set MySQL int column to auto increment by 1 beginning at 10000?
- Changing the current count of an Auto Increment value in MySQL?
Advertisements