[go: up one dir, main page]

0% found this document useful (0 votes)
103 views1 page

Database - Second Normal Form 2

The document discusses second normal form (2NF) in database design. It states that for a table to be in 2NF, it must meet all criteria for 1NF and cannot have non-key columns that depend on only part of a composite primary key. An example table is given that is in 1NF but not 2NF, and it is shown how to decompose it into three tables to satisfy 2NF.

Uploaded by

usermani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
103 views1 page

Database - Second Normal Form 2

The document discusses second normal form (2NF) in database design. It states that for a table to be in 2NF, it must meet all criteria for 1NF and cannot have non-key columns that depend on only part of a composite primary key. An example table is given that is in 1NF but not 2NF, and it is shown how to decompose it into three tables to satisfy 2NF.

Uploaded by

usermani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

DATABASE - SECOND NORMAL FORM 2NF

http://www.tutorialspoint.com/sql/second-normal-form.htm Copyright tutorialspoint.com

Second normal form states that it should meet all the rules for 1NF and there must be no partial
dependences of any of the columns on the primary key:

Consider a customer-order relation and you want to store customer ID, customer name, order ID
and order detail, and date of purchase:

CREATE TABLE CUSTOMERS(


CUST_ID INT NOT NULL,
CUST_NAME VARCHAR (20) NOT NULL,
ORDER_ID INT NOT NULL,
ORDER_DETAIL VARCHAR (20) NOT NULL,
SALE_DATE DATETIME,
PRIMARY KEY (CUST_ID, ORDER_ID)
);

This table is in first normal form, in that it obeys all the rules of first normal form. In this table, the
primary key consists of CUST_ID and ORDER_ID. Combined, they are unique assuming same
customer would hardly order same thing.

However, the table is not in second normal form because there are partial dependencies of
primary keys and columns. CUST_NAME is dependent on CUST_ID, and there's no real link between
a customer's name and what he purchased. Order detail and purchase date are also dependent on
ORDER_ID, but they are not dependent on CUST_ID, because there's no link between a CUST_ID
and an ORDER_DETAIL or their SALE_DATE.

To make this table comply with second normal form, you need to separate the columns into three
tables.

First, create a table to store the customer details as follows:

CREATE TABLE CUSTOMERS(


CUST_ID INT NOT NULL,
CUST_NAME VARCHAR (20) NOT NULL,
PRIMARY KEY (CUST_ID)
);

Next, create a table to store details of each order:

CREATE TABLE ORDERS(


ORDER_ID INT NOT NULL,
ORDER_DETAIL VARCHAR (20) NOT NULL,
PRIMARY KEY (ORDER_ID)
);

Finally, create a third table storing just CUST_ID and ORDER_ID to keep track of all the orders for a
customer:

CREATE TABLE CUSTMERORDERS(


CUST_ID INT NOT NULL,
ORDER_ID INT NOT NULL,
SALE_DATE DATETIME,
PRIMARY KEY (CUST_ID, ORDER_ID)
);
Loading [MathJax]/jax/output/HTML-CSS/fonts/TeX/fontdata.js

You might also like