C
C
cdfgharweer332018-10-20 16:02:50
SQLite
cdfgharweer33, 2018-10-20 16:02:50

How to update a table after deletion?

I have a SQLite database with an ID (primary key) column. When an entry is deleted, for example, with ID 1, the entries in the table go further from 2 (ID 1 is empty). How to update ID after deletion? So that ID 1 has a record from ID 2, etc.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
S
Sergey Gornostaev, 2018-10-20
@sergey-gornostaev

Identifiers should not change, that's their whole point.

C
cdfgharweer33, 2018-10-20
@cdfgharweer33

Perhaps someone will come in handy, solved the problem like this.
UPDATE table SET id = id - 1 WHERE id > ?

Y
yalex1442, 2015-08-09
@yalex1442

instead of executing the task, you can put a mark on the task in the queue, then a separate script will process the tasks
habrahabr.ru/post/123451

V
Valery Ryaboshapko, 2015-08-09
@valerium

MySQL has two ways to store time - Datetime and Timestamp. Details about the differences in the documentation, in your case it is not critical.
Cron once per minute is the worst thing you can think of. It is better to simply store the publication date and time and add a condition to the SQL query that will discard records with a publication time greater than the current one.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question