This is the order Supplier → Purchase Detail → Product. At the point where the Purchase Detail table is added second, the Product table still has no row for the new product. The Product Code in the Purchase Detail table is a foreign key referring to the Product table, so the target it refers to does not exist and referential integrity is violated. Product must be added before Purchase Detail.
○イ
正解The correct answer is イ (the “Supplier” table → the “Product” table → the “Purchase Detail” table). A foreign key is a column whose value refers to a primary key value in another table. If you add a row on the referencing side while the row it refers to does not exist yet, you create a reference that points nowhere (a violation of referential integrity). Data must therefore always be added starting from the referenced side (the parent) table. In the figure, the three tables form a one-way chain of references: the Supplier Code in the Product table (dashed line = foreign key) refers to the Supplier Code in the Supplier table (primary key), and the Product Code in the Purchase Detail table (dashed line = foreign key) refers to the Product Code in the Product table (primary key). In other words, Supplier is the top-level parent, Product is in the middle, and Purchase Detail is the lowest-level child. Because this time a new product was purchased from a new supplier, you first register that supplier in the Supplier table so that its supplier code really exists, next register in the Product table the product carrying that supplier code so that its product code really exists, and finally register in the Purchase Detail table the purchase line that uses that product code. Only this order, Supplier → Product → Purchase Detail, keeps the target of every foreign key already in place at every stage.
×Incorrectウ
This is the order Purchase Detail → Product → Supplier, in which the parent-child relationship is completely reversed. The Product Code in the Purchase Detail table added first has no target to refer to (the Product table), and the Supplier Code in the Product table that comes next has no target either (the Supplier table). An order that works back up from child to parent fills in the tables holding foreign keys first, so it is always inappropriate.
×Incorrectエ
This is the order Product → Supplier → Purchase Detail. Putting Purchase Detail last is correct, but at the point where the Product table is added first, the Supplier table still has no row for the new supplier. The Supplier Code in the Product table is a foreign key referring to the Supplier table, so referential integrity is violated at that point. Supplier must come before Product.
ここがポイント
Foreign keys and referential integrity: the value of a foreign key must be a primary key value that really exists in the referenced table. For this reason data is added in the order parent (referenced table) to child (referencing table), and deleted in the opposite order, child to parent.
Reading the chain of references from the figure: by following which solid line (primary key) each dashed line (foreign key) points to, you can see the reference direction Purchase Detail → Product → Supplier. The order for adding data is the reverse of that: Supplier → Product → Purchase Detail.