Processing SortOrder fields in SQL Server

In a specific table, I have an integer field SortOrder that tells my page in which order to display the data. There are data sets in this field (based on the CategoryID field), and each set will have its own order. Users can add / delete / update entries in this table.

My question is the best way to manage this SortOrder field? I would like to β€œreseed” it every time a record is deleted or updated. For this, should I use a trigger? Or should my code handle it and control repetition?

+3
source share
2 answers

What I used is to use only odd numbers in the SortOrder field, so by changing the order I would add or subtract 3 from the current value of the changed item and then reload (order the items again using an odd number of indices). Also I used reseed after every insert or delete.

+2
source

, , . , , , . , , . , , , . , - . ( , , , . , ORDER BY. .)

+1

Source: https://habr.com/ru/post/1723712/


All Articles