Tuesday, January 27, 2015

[MySQL] How to know AUTO_INCREMENT value on some tables?

  Hi there~! Today we will study about mysql auto_increment value. When you create some tables that needs index number column, you will set auto_increment on that column. Yeah it's natural. Sometimes we need to know auto_increment value. Then after insert date, you call mysql_insert_id() function or like that. But if you need to know auto_increment value before inserting?

  If you want to know auto_increment value, you have to know this query.

SELECT AUTO_INCREMENT FROM information_schema.TABLES WHERE TABLE_SCHEMA = "databaseName" AND TABLE_NAME = "tableName"

[Execution query in phpmyadmin]


 In addition, you have only one database, you can use this query.
SELECT AUTO_INCREMENT FROM information_schema.TABLES WHERE TABLE_NAME = "tableName"
[Execution query in phpmyadmin]



Did you get it? Go and Testing!

No comments:

Post a Comment