Answer the question
In order to leave comments, you need to log in
How can I set up an auto-incrementing column so that no gaps appear when new rows are added?
Table
ID : INT UNSIGNED
USER_ID : BIGINT
TITLE : VARCHAR(500)
CHECKED : BOOL
I make a query like this:
INSERT INTO `testDB`.`table1` (`USER_ID`, `TITLE`, `CHECKED`) VALUES ('707', 'ExmpleString', '0');
DELETE FROM `testDB`.`table1` WHERE (`ID` = '11');
INSERT INTO `testDB`.`table1` (`ID`, `USER_ID`, `TITLE`, `CHECKED`) VALUES ('2', '707', 'ExmpleString', '0');
Answer the question
In order to leave comments, you need to log in
Ok, let's imagine that you set up a similar mechanism (although it is obvious that this was done for a reason), and now you have, let's say, users with numbers 10 and 11. Each of them has some data that is tied to this user by id. Now we are deleting user number 10 and then creating a new one to take that place. Now the owner of all the data of the deleted user will be the new user, who, as it were, should not have access to them.
This is a banal and simplest example, more to understand... A unique identifier is unique for that, that it will no longer be repeated and guarantees this non-repeatability at the level of the database mechanism.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question