What is Second Normal Form?
- In a Relational Database Management System, data consistency and dependency are of utmost importance. Generally, the Normal forms are used to avoid redundancy of data. Redundancy in the data leads to anomalies such as update, insert and delete. In update anomaly, if a table has redundant data, then while updating the records, they are not correctly updated which results in the data being inconsistent.
- In the case of insert anomaly, we can understand it better by taking an example of a column that cannot be updated with null values if the table does not allow null values. The delete anomaly comes into the picture, if we need to delete a certain record and if that record is present in other rows of the table, then deleting that specific record, will delete the record from the other rows too.
- To overcome the update, insert and delete anomalies, the data needs to be normalized. Normalization eliminates redundant data and also ensures the data dependencies. Also, Normalization helps to store the data logically and reduce the space to store the database.
- Various Normal forms that are commonly used in Relational Database Management System are First Normal Form, Second Normal Form, Third Normal Form, Boyce-Codd Normal Form (BCNF), etc. In order to achieve the Second Normal form, the First Normal Form should be achieved first which is one of the criteria of making the table or data to be in Second Normal Form. The rule for First Normal Form (1NF) is that an attribute of a column cannot contain multiple values rather it should hold atomic values.
How Does Second Normal Form work?
Before going deep into the concept of Normalization, let us focus on a few fundamental elements involved in database tables and relations. A Key in RDBMS is used to identify records uniquely in a table and a key can be a single column or multiple columns. A Primary key is a single column that is used to identify the records uniquely. A composite primary key consists of multiple columns, which is also used to identify unique records. In the Second Normal Form, we need to achieve a single-column primary key. A Foreign key in one table is used to identify the records in another table uniquely. In Second Normal Form, each non-key attribute in the relation must depend upon the primary key functionally.
Below are a few steps to ensure the data is in the Second Normal Form:
- First Normal Form should be achieved.
- Removing subsets of data that is applicable to multiple rows in a table and placing them in different tables.
- Using foreign keys to ensure relationships between the created tables.
To understand the normal forms better, let us take the example of the below table and then the steps to achieve the Second Normal Form.
Let us take the example of the below table ‘teacher_details’.
|1289||Ramesh Sawant||Math, Science|
|1267||Nikhil Das||History, Social Studies|
The above table contains the specific subjects taught by each teacher. Here the ‘Subjects’ columns do not contain atomic values and for Id 1289 and 1267, there is more than one subject present in the ‘Subjects’ column. As we can see that the column ‘Subjects’ does not have atomic values, we need to first make the table compliant to First Normal Form by following the below.
|1267||Nikhil Das||Social Studies|
Now the above table is in First Normal Form as all the attributes have atomic value.
Here the composite primary keys are ‘Id’ and ‘Name’. The column ‘Subjects’ is the non-prime attribute. Also here the column ‘Subjects’ is only dependent upon the column ‘Name’ which is part of the composite primary key. So the table does not fulfill the condition of the Second Normal Form.
To make the table compliant to Second Normal Form, we need to break the above table into the two tables as shown below.
Table teacher_info as shown below:
Table subject_details as shown below:
We have removed the initial functional dependency from the table. So in the table subject_details, the column ‘Subjects’ is fully dependent upon the primary key of the table i.e. ‘Id’.
Advantages of Second Normal Form
Below are a few of the advantages of using the second normal form.
- Redundant data is reduced more effectively.
- Data is consistent in the database.
- It improves the flexibility in designing a Database.
- It also improves the overall organization of data in the database.
- It also improves the security of the database.
- For the successful implementation of a Database Management System, which meets the requirements of data of an Enterprise system, the designing of a database is critical. Normalization helps in achieving the designing as well as the maintenance of a Database Management System by ensuring data consistency and dependency.
- Though the Second Normal Form removes the subsets of data which is applicable to multiple rows in a table and ensures the relation among tables by using the foreign key, still the need for removal of transitive functional dependency of the non-prime attribute on any super key gives rise to the usage of Third Normal Form. So the usage of the Second Normal Form depends upon the requirement set by the business and it should be chosen carefully while designing the Database Management System.
This has been a guide to Second Normal Form. Here we have discuss what is Second Normal Form? How does the second normal form work? along with an appropriate example. You can also go through our other suggested articles to learn more –