Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem with auto-incremented "id" column

My db table looks like this pic. http://prntscr.com/22z1n

Recently I've created delete.php page. it works properly but when i deleted 21th user next registered user gets 24th id instead of 21.

Is it possible to put newly registered users info to first empty row? (In this situation 21th row)

In my registration form, newly registering user can write names of existing users, and be friends with them after registration. For this friendship i have another table that associates id of newly registered user and existing user.

For this purpose i'm using mysql_insert_id during registration to get id for new user. But after deletion of 21th row during nex registration process mysql_insert_id gave me number 21. but stored in 24th row. And put to associations table 21 for new user. I wanna solve this problem

like image 852
Tural Ali Avatar asked Jun 17 '11 20:06

Tural Ali


1 Answers

When you use an autoincrement id column, the value that the next entry will be assigned will not be reduced by deleting an entry. That is not what an autoincrement column is used for. The database engine will always increment that number on a new insert and never decrement that number on a delete.

like image 175
mkro Avatar answered Sep 23 '22 02:09

mkro