Answers:
链表只是一个非常简单的有向无环图。没有理由为什么这很难解决,或者对于SQL Server应该避免。
考虑一下,树结构比链表更复杂。Internet上将数据存储在关系数据库中的论坛的每种实现都实现了链接列表的基础。在此页面上,答案形成一个链接列表。可以添加和删除它们。他们可以移动位置(又名,按投票排名)。
要使用的特定表示形式仅取决于您希望在维护列表(插入,更新,删除)和检索之间进行权衡。
--Works great for INS/UPD/DEL, In order retrieval isn't the best.
CREATE TABLE Item (id int identity, next int, prev int)
--makes in order retrieval fast, deletes are a problem, inserts may require re-numbering.
CREATE TABLE Item (id int identity, position int )
--Works great for in-order retrieval, and allow cheap insertion/deletion,
--certain edge cases might be tricky to handle.
CREATE TABLE (id int identity, position Decimal(24,12 ) )
--for inserts, use the average of the before and after, for deletes, just delete.
更新:问题是关于SQL Server中的树与链表
SQL Server具有HierarchyId数据类型,该数据类型旨在简化树状结构的实现和查询。
CREATE TABLE Item (id int identity, NodeId HierarchyId)