The First normal form (1NF) sets basic rules for an organized database −
Define the data items required, because they become the columns in a table.
Place the related data items in a table.
Ensure that there are no repeating groups of data.
Ensure that there is a primary key.
You must define the data items. This means looking at the data to be stored, organizing the data into columns, defining what type of data each column contains and then finally putting the related columns into their own table.
For example, you put all the columns relating to locations of meetings in the Location table, those relating to members in the MemberDetails table and so on.
The next step is ensuring that there are no repeating groups of data. Consider we have the following table −
CREATE TABLE CUSTOMERS( ID INT NOT NULL, NAME VARCHAR (20) NOT NULL, AGE INT NOT NULL, ADDRESS CHAR (25), ORDERS VARCHAR(155) );
So, if we populate this table for a single customer having multiple orders, then it would be something as shown below −
|100||Sachin||36||Lower West Side||Cannon XL-200|
|100||Sachin||36||Lower West Side||Battery XL-200|
|100||Sachin||36||Lower West Side||Tripod Large|
But as per the 1NF, we need to ensure that there are no repeating groups of data. So, let us break the above table into two parts and then join them using a key as shown in the following program −
CUSTOMERS table −
CREATE TABLE CUSTOMERS( ID INT NOT NULL, NAME VARCHAR (20) NOT NULL, AGE INT NOT NULL, ADDRESS CHAR (25), PRIMARY KEY (ID) );
This table would have the following record −
|100||Sachin||36||Lower West Side|
ORDERS table −
CREATE TABLE ORDERS( ID INT NOT NULL, CUSTOMER_ID INT NOT NULL, ORDERS VARCHAR(155), PRIMARY KEY (ID) );
This table would have the following records −
The final rule of the first normal form, create a primary key for each table which we have already created.
80 Lectures 6.5 hours