What's the best way to store sort order in SQL?

后端 未结 5 1122
栀梦
栀梦 2020-12-29 02:09

The guys at the top want sort order to be customizable in our app. So I have a table that effectively defines the data type. What is the best way to store our sort order. If

5条回答
  •  粉色の甜心
    2020-12-29 03:08

    Use an int field. When you update the sort order of one row, you only have to update the field on the row you're updating and any rows between the row's old and new positions. This means that swapping two rows only involves touching those two rows. Also, for rows you're updating that aren't your "active" row, you only need to increment or decrement the field; the queries are easy to write.

提交回复
热议问题