Create foreign key after normalization
source link: https://www.codesd.com/item/create-foreign-key-after-normalization.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Create foreign key after normalization
I've been creating a database, and I've just completed the normalization step. One of the relations violated the 2NF through partial dependency, so i split it into two relations, as per normalization guidelines. What i was wondering was, for the new relation that i created, does it have a foreign key that relies upon the primary key of the original relation?
For example;
Before normalization: R{PK1, PK2, attr1, attr2}
After normalization: R1{PK1, PK2, attr1} R2{PK2, attr2}
Should PK2 have foreign key with PK1?
Thanks for any help
since attr2 is functionally dependent on only PK2, attr2 has the same value for all rows that have PK2 with a given value. If you added PK1 to R2, you would have two choices, both bad.
You could have only one row in R2 for each value of PK2, in which case you are limited to one value for PK1. This overconstrains your data.
You could have many rows in R2, all with the same value of PK2 but each with a different value for PK1. Now you aren't in 2NF any more, and you're back where you started.
Related Articles
The foreign key constraint fails with & ldquo; Error creating foreign key on [table] (check datatypes) & rdquo;
SQLAlchemy does not create foreign keys on MySQL [Debian Linux]
Jet / Access DDL: How to create FOREIGN KEY constraints without checking data integrity?
How to create foreign keys in Azure DB?
Create foreign keys from Rails associations
Trouble creating foreign keys in mySql
SQL Server - Create Foreign Key on Multiple Tables
Unable to create FOREIGN KEY CONSTRAINT in MySQL
Error Creating Foreign Key in Product Table
Hibernate does not create foreign key
MySQL can not create foreign key constraint
Can I create foreign keys in databases?
Tips for creating foreign keys in an existing database
How do I create foreign keys for the junction table
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK