I was never doing self-referencing tables (I didn't dive into it yet), but accidentally I went to this moment I guess
Let's say that we have a table named "Human"
// [Human]
ID
Name
Surname
...
father
The father column is also Human (captain obvious) instance, so father column should be a reference to [Human].ID ?
For some reason it is hard to imagine for me, first occurence of INSERT can't contain reference to itself so father should be nullable (let's dont go into logic behind this, some data can be unknown). This eliminates paired PK columns in table
I made more complex image of this
您可以为“未知”人插入一行,然后父亲不明的人可以引用未知人的ID
Unless you plan to store data on every human who ever lived, you're eventually going to have someone without a father record (and even then: who is your first human's father). In other words, yes, the column needs to be nullable.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.