M
M
Meliborn2011-04-19 23:54:37
MySQL
Meliborn, 2011-04-19 23:54:37

Restoring numbering in the database, the field is not auto-increment?

There is a table. 8 entries are entered into the table with each addition (1 pack = 8 entries). These eight records have a field responsible for the position, respectively, it is the same for each pack.
For the first eight it will be 1, for the second eight it will be 2, and so on. (I would kill for such an organization). After the pack is removed, the sequence is broken.
For example, if you deleted the second pack, then there are 8 records left with the value 1 and 8 with the value 3.
The question is: how to return the sequence to each pack after each deletion?
MySQL, I didn't write it, they asked me to fix it. I'm shocked.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
E
ertaquo, 2011-04-20
@ertaquo

Maybe so?
UPDATE table SET index = index - 1 WHERE index > 2

B
bubuq, 2011-04-20
@bubuq

Eh ... well then:

Select @i:=0; Update TBL Set index = @i := @i +1, index = floor(index/8);

B
BearOff, 2011-04-21
@BearOff

And why, in fact, hole-free is required?

B
bubuq, 2011-04-20
@bubuq

What does "return sequence" mean? If pack 2 is deleted, then all packs from number 3 to the last should be updated, right? And if not a complete pack is removed, can it be? What if it's added?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question