6

Create foreign key after normalization

 3 years ago
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.
neoserver,ios ssh client

Create foreign key after normalization

advertisements

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.

  1. 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.

  2. 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;

The following query fails with error "Error creating foreign key on city (check data types)": ALTER TABLE `hotels` ADD FOREIGN KEY ( `city` ) REFERENCES `mydatabase`.`cities` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ; Basically I want to have

SQLAlchemy does not create foreign keys on MySQL [Debian Linux]

For same code snippet, SQLAlchemy creates Foreign Key constraint on Mac OX, however, it fails to create foreign key constraint on Debian Linux. Environment & Libraries: Python 2.7 SQLAlchemy 0.7.8 MySQL-python-1.2.3 [This is the connector, and I am s

Jet / Access DDL: How to create FOREIGN KEY constraints without checking data integrity?

When you create foreign key constraints with Access (through database schema editor), you have a choice to enable or disable the following options (actual captions may differ, I only have localized version of Access available): x Enforce data integri

How to create foreign keys in Azure DB?

How do I create foreign keys in Azure DB ? I can't find it in the silver-light Azure DB manager and when I connect with SSMS, when I don't get the same GUI options to add foreign keys. Do I really have to use manually written scripts to accomplish th

Create foreign keys from Rails associations

How to automatically create foreign keys from Rails associations? The best solution should generate Rails database migration from Rails associations.For that you can use the immigrant gem. Take a look at https://github.com/jenseng/immigrant copy/past

Trouble creating foreign keys in mySql

I created a foreign key in my sql by the following statemnt.. ALTER TABLE `users` ADD FOREIGN KEY ( `id`) REFERENCES `user_login` (`user_id`) ON DELETE CASCADE ; The creation appears to succeed then after that I execute a delete statement DELETE From

SQL Server - Create Foreign Key on Multiple Tables

I have a requirement where I need to create a foreign key for more than 200 tables. Ex, there is emp table which has ID has primary key, now the 200 tables have emp_id, which I need to reference to emp.id. I know I can write 200 alter statements to c

Unable to create FOREIGN KEY CONSTRAINT in MySQL

I created my MySQL database using phpMyAdmin 3.5.8.1deb1 in Ubuntu. Instead of that all my tables are InnoDB, I can't add a foreign key, and this is an example: ALTER TABLE element ADD CONSTRAINT FK_element_id_user FOREIGN KEY (id_user) REFERENCES us

Error Creating Foreign Key in Product Table

I have created a table Suppliers n MySQL Suppliers Description: Supplier_ID varchar(5) NOT NULL Supplier_Name varchar(30) Supplier_Address varchar(50) Supplier_Contact int(12) Supplier_Email varchar(30) PRIMARY KEY(Supplier_ID) Now, I want to create

Hibernate does not create foreign key

I have three class with onetomany and manytoone annotated. Below Category.java @Entity public class Category implements Serializable { @Id @GeneratedValue int id; String cat; @OneToMany(cascade= CascadeType.ALL) @JoinColumn(name="cat_id") privat

MySQL can not create foreign key constraint

I'm having some problems creating a foreign key to an existing table in a mysql database. I have the table exp: +-------------+------------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------------+---------

Can I create foreign keys in databases?

We have 2 databases - DB1 & DB2. Can I create a table in DB1 that has a relation with one of the tables in DB2? In other words, can I have a Foreign Key in my table from another database? I connect to these databases with different users. Any ideas?

Tips for creating foreign keys in an existing database

I've got a database that doesn't have any foreign keys. I've done some checks and there are a a fair few orphaned records. Its a pretty large database 500 + tables and I'm looking at the possibility of building the foreign keys back in. Other than tr

How do I create foreign keys for the junction table

I have Object1 and junction table and Object2. Object2 is table that has many junction tables, but can have only one junction table torefrencing to it. When table Object1 is removed, then junction table and Object2 should be removed. How can I make f

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK