create a triggers in mysql that reorganize the numbering of a field when one of these fields is excluded

1

I have a users table containing the following column:

note that the position numbering is in order, what I want is when you delete some user to trigger rearrange the numbering, ie if you delete Josefa and Pedro, Jone becomes position 2 and Soares becomes position 3 .

    
asked by anonymous 15.12.2016 / 13:33

1 answer

0

I do not know how triggers work in MySQL, but in theory, you only need to decrement all positions below the one you removed, it's a simple SQL:

update usuarios set posicao = posicao - 1 where posicao < ?

Where "?" is the position of the user that was removed.

    
15.12.2016 / 14:39