Contents
Can foreign key refer to same table?
A foreign key constraint doesn’t have to be linked only to a primary key constraint in another table. FOREIGN KEY constraints can reference another column in the same table, and is referred to as a self-reference. A FOREIGN KEY constraint specified at the column level can list only one reference column.
What could the foreign key of a table reference?
A foreign key is a column (or combination of columns) in a table whose values must match values of a column in some other table. FOREIGN KEY constraints enforce referential integrity, which essentially says that if column value A refers to column value B, then column value B must exist.
Can you have a foreign primary key?
Yes, it is legal to have a primary key being a foreign key. This is a rare construct, but it applies for: a 1:1 relation. The two tables cannot be merged in one because of different permissions and privileges only apply at table level (as of 2017, such a database would be odd).
Can a foreign key refer to a primary key in the same table?
Now, d_id is foreign key so how it can be a primary key. And explain something about join. What is its use? I think the question is a bit confusing. If you mean “can foreign key ‘refer’ to a primary key in the same table?”, the answer is a firm yes as some replied.
Is there any reason for primary key referencing itself?
In practice, ItemID refers to tblItem.ItemID, and ItemListID is found nowhere else in the DB but there is a corresponding enum in the application. Is there any reason for the primary key to also be a foreign key referencing itself (ie. some undocumented performance improvement), or is it just a mistake?
Which is the record of the same table?
And mother and father both are themselves a person.. so, they are itself a record of the same table.. So, from the above table you see that, person with id = 5 is actually mother of person with id = 1 ..