Join a table to itself

后端 未结 7 1327
Happy的楠姐
Happy的楠姐 2021-01-26 00:15

this is one on my database tables template.

Id int PK
Title nvarchar(10) unique
ParentId int 

This is my question.Is there a problem if i creat

7条回答
  •  不要未来只要你来
    2021-01-26 00:39

    It is fine to do this (it's a not uncommon pattern). You must ensure that you are adding a child record to a parent record that actually exists etc., but there's noting different here from any other constraint.

    You may want to look at recursive common table expressions:

    http://msdn.microsoft.com/en-us/library/ms186243.aspx

    As a way of querying an entire 'tree' of records.

提交回复
热议问题