在数据库中的行之间存储顺序的最佳方法是什么? [英] What is the best way to store the order between rows in the database?
问题描述
该应用程序是为Google AppEngine(Python)制作的。
使rowNumber成为一个浮点数。当用户插入行 x 和 y 之间时,新行将获得rowNumber =(x.rowNumber + y.rowNumer)/ 2.
当您要移动一行时,只需按照目标位置相同的方式更新其rowNumber。
新行获取rowNumber。 MAX + 256。
编辑 Microsoft在SQL Server 2008中使用新的HierarchyId数据类型解决了这一点。您可以根据需要在两个几个之间插入多个次数 - 直到用完HierarchyId最大大小。
I am cloning and extending the Google Tasks application. I want to be able to store the rows order. I have created a field in the database, named rowNumber. When the user inserts a row in the middle of others, I have to update this field in many other rows to achieve the desired output. There is a better way to do it?
BTW the application is made for the Google AppEngine (Python).
Make rowNumber a floating point number. When user inserts between rows x and y, the new row gets rowNumber = (x.rowNumber + y.rowNumer) / 2.
When you want to move a row, just update its rowNumber the same way based on target position.
New rows get rowNumber eg. MAX + 256.
Edit Microsoft solved this in SQL Server 2008 using new HierarchyId datatype. You can insert between 2 items almost as many times as you want - until you run out of HierarchyId max size.
这篇关于在数据库中的行之间存储顺序的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!