How to get the next auto-increment id in mysql

faressoft picture faressoft · Jul 20, 2011 · Viewed 229.5k times · Source

How to get the next id in mysql to insert it in the table

INSERT INTO payments (date, item, method, payment_code)
VALUES (NOW(), '1 Month', 'paypal', CONCAT("sahf4d2fdd45", id))

Answer

ravi404 picture ravi404 · Sep 19, 2012

You can use

SELECT AUTO_INCREMENT
FROM information_schema.tables
WHERE table_name = 'table_name'
AND table_schema = DATABASE( ) ;

or if you do not wish to use information_schema you can use this

SHOW TABLE STATUS LIKE 'table_name'