Hi all,
When you add integer ID primary key auto increment, it automatically makes ID for you. But I was pondering on what happens after deleting a record. Does the server automatically adjust all IDs for you or it remains un assigned?

For example, I have inserted as follows
+------------+-------------+
| 1 | Orange |
|-------------+-------------+
| 2 | Banana |
|-------------+-------------+
| 3 | Mango |
|-------------+-------------+

If I delete Banana, what happens to ID no 2

Recommended Answers

All 4 Replies

Once its deleted it won't be used again (unless you truncate the table). MySQL will not reassign the ids, as it would defeat the purpose of using them. Once you set an id, it should never change.

Good explanation. But what happens after a deleting and adding let say millions of user? Wont Database become clogged?

If you used an INT(11) data type I belive the max ID would be 4,294,967,295 which would be about the total online community of the entire planet, so a very large user base :-)

I think you'll hit other server side issue long before you hit the ID limit, i.e disk space, too many concurrent users etc.

Hope this helps you sleep easier.

If you used an INT(11) data type I belive the max ID would be 4,294,967,295 which would be about the total online community of the entire planet, so a very large user base :-)

I think you'll hit other server side issue long before you hit the ID limit, i.e disk space, too many concurrent users etc.

Hope this helps you sleep easier.

Thanks all guys. It have been alot of learning and fun:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.