How can I reorder rows in sql database

后端 未结 14 1837
忘了有多久
忘了有多久 2020-11-28 03:24

Is it possible to reorder rows in SQL database? For example; how can I swap the order of 2nd row and 3rd row\'s values?

The order of the row is important to me since

14条回答
  •  野性不改
    2020-11-28 03:47

    The question lacks any detail that would let anyone give you correct answer. Clearly you could read the records into memory and then update them. But this is bad on so many different levels.

    The issue is like this. Depending on the schema that is actually implemented there is logic to the way that the records are physically written to disk. Sometimes they are written in order of insert and other times they are inserted with space between blocks (see extents).

    So changing the physical order is not likely without swapping column data; and this has a deep effect on the various indices. You are left having to change the logical order.

    As I read your update... I'm left to understand that you may have multiple users and each user is to have bookmarks that they want ordered. Looks like you need a second table that acts as an intersection between the user and the bookmark. Then all you need is an inner join and an order by.

    But there is not enough information to offer a complete solution.

提交回复
热议问题