- 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
MySQL query to get the next number in sequence for AUTO_INCREMENT field?
Let us first create a table −
mysql> create table DemoTable -> ( -> Id int NOT NULL AUTO_INCREMENT, -> PRIMARY KEY(Id) -> ); Query OK, 0 rows affected (0.58 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values(); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values(); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values(); Query OK, 1 row affected (0.12 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
Output
This will produce the following output −
+----+ | Id | +----+ | 1 | | 2 | | 3 | +----+ 3 rows in set (0.00 sec)
Following is the query to get the next number in sequence for AUTO_INCREMENT field −
mysql> SELECT auto_increment FROM information_schema.tables WHERE table_name='DemoTable';
Output
This will produce the following output −
+----------------+ | AUTO_INCREMENT | +----------------+ | 4 | +----------------+ 1 row in set (0.26 sec)
- Related Articles
- On inserting ‘NULL’, ‘0’ or No Value to the column, will MySQL assign sequence number for AUTO_INCREMENT column?
- MySQL query to get next closest day between two days?
- MySQL query to get the count of all the elements in the field?
- How do you find out which sequence number was assigned recently by MySQL AUTO_INCREMENT?
- MySQL query to get the max value with numeric values in varchar field?
- How do I get the current AUTO_INCREMENT value for a table in MySQL?
- MySQL database field type for search query?
- What MySQL returns when we alter AUTO_INCREMENT value which is less than current sequence number?
- How to get the possible values for SET field in MySQL?
- Create table query with manual AUTO_INCREMENT start value in MySQL?
- Can I find out the next auto_increment to be used?
- MySQL query to set current date in the datetime field for all the column values
- MySQL query to get a field value that does not contain empty spaces?
- How to get the next auto-increment id in MySQL?
- MySQL query to select records approaching in next 12 hours?

Advertisements