Updating an “order” column MySQL?

前端 未结 2 1799
面向向阳花
面向向阳花 2021-01-22 00:45

What\'s the best way to update an \"order\" column?

Say I have an id column with 0 to 9, and order column from 0 to 9.

Currently, it\'s in the database as: 0 0,

2条回答
  •  孤独总比滥情好
    2021-01-22 01:07

    If the user really is reordering the items at random, there isn't much you can do. But typically a user might make a small modification to an existing ordering, such as moving one item higher up in the list. In this case you can make a minor speed improvement by relaxing your constraint that the sort order column must contain sequential integers. I discussed a possible idea for this before here and you can read that suggestion if you're interested in the details of how to implement this.

    But for lists of size 10 it's probably not worth the extra effort. Just do what you are doing - it'll probably be just fine in practice.

提交回复
热议问题