I have a table with an id,name,order_index
.
The order_index must be unique, therefore a unique constraint is defined.
Lets say it is stored
id,name,order_index
1 ,'a',1
2 ,'b',2
3 ,'c',3
and then a new order must be saved:
id:1 gets order_index 2.
id:2 gets order_index 1.
Then a foreign key violation happens.
It would be possible to have an intermediate query to set an order_index to e.g. 4. But is there a more convenient solution for that?