Reputation: 115
What's the best way to track display order in a database? I have been using integers (1 being displayed first and something like 5 last) but worry about corrupting the data somehow.
Is there a better way?
Upvotes: 1
Views: 257
Reputation: 12843
For simple display purposes I usually use a simple integer with increments of 10 if the number is to be manipulated manually. That leaves room for a few adjustments. Or if the number is maintained by code, I go with increments of 1.
When I model something more "important" or busineslike, I usually consider an adjacency list model.
Performance and scalability may be of concern here, because if you use a number in a list of 10,000 items, you may have to lock/update 10,000 rows. Of course, you could always use larger increments and be peeky & sneaky at the cost of more complexity.
The adjacency list does not have this problem, but is more difficult to query on the other hand.
Upvotes: 2