Gapchoos
Gapchoos

Reputation: 1422

Reusing AUTO INCREMENT ID

I would like to reuse an AUTO INCREMENT ID that is being deleted. am using the MySQL database.

Thanks in Advance

Upvotes: 1

Views: 823

Answers (2)

Ajay Kadyan
Ajay Kadyan

Reputation: 1079

SELECT id + 1 FROM TableName t1 WHERE NOT EXISTS (SELECT 1 FROM TableName t2 WHERE t2.id = t1.id + 1) limit 0,1

Upvotes: 2

Ajay Kadyan
Ajay Kadyan

Reputation: 1079

To find that you can use this

SELECT Auto_increment FROM information_schema.tables WHERE table_name='tableName'  AND table_schema = 'dataBaseName';

Upvotes: 0

Related Questions