R
R
Roman2021-09-19 20:02:31
MySQL
Roman, 2021-09-19 20:02:31

Reassign id in table?

There is a task to reassign all IDs in the table, as a result I found the following code:

set @i := -1;
update tablename set id = (@i := @i+1 ) order by id;

Only he sets the order from scratch, but I need from one. Tried to change set to 0, swears at a double by key. Ideally, change the value in the links, but I'm not sure that it can be implemented with one request.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Slava Rozhnev, 2021-09-19
@rozhnev

In principle, a bad idea, but if you really want to, then delete the Id column and create it again

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question