问题
In a One to Many association between a Parent Table and Child Table.
Is it ok to make the Foreign key on the Child table as the Primary key on the same child table.
Just working my way through DBMS and would appreciate expert views on these type of designs.
What are the Pros and Cons?
回答1:
If you mean one parent row maps to many child rows, then you won't be able to do that. Primary key values come with unique key constraints; if you need multiple child rows to reference the same parent, setting the foreign key reference as the primary key will disallow that, because you won't be able to have more than one row with the same foreign key reference.
回答2:
That would create a 1:0-1 relationship, not a 1:0-n, since defining the foreign key that relates the child to the parent as the child's primary key would prevent you from having more than one child with the same parent key.
来源:https://stackoverflow.com/questions/4857935/having-a-foreign-key-as-the-primary-key-in-a-child-table