2nd Normal Form in SQL
Second Normal Form in SQL DataBase
In 2nd Normal form maintain the 1st Normal form and remove the partial function dependency. For a table to be in the Second Normal Form,
- It should be in the First Normal form
- It should not have Partial Dependency
What is Dependency
We take example of a Employee table with columns EMP_id, Name, Mobile_No and Dept.
EMP_id | Name | Mobile_No | Dept |
---|---|---|---|
In Employee table, EMP_id is the primary key and will be unique for every row, hence we can use EMP_id to fetch any row of data from this table
Even for a case, where student names are same, if we know the EMP_id we can easily fetch the correct record.
EMP_id | Name | Mobile_No | Dept |
---|---|---|---|
101 | Hitesh | 8076671483 | HR |
105 | Hitesh | 8882538826 | Support |
Hence we can say a Primary Key for a table is the column or a group of columns(composite key) which can uniquely identify each record in the table.I can ask from branch name of Employee with EMP_id 101, and I can get it. Similarly, if I ask for name of Employee with EMP_id 101 or 105, I will get it. So all I need is EMP_id and every other column depends on it, or can be fetched using it. This is Dependency and we also call it Functional Dependency.
Any Candidate key (K) and any Attribute (A) that is not a constituent of a candidate key, A depends upon whole of K rather than just part of it This means all its non-prime attributes are functionally dependent on the whole of a candidate key.
In Simple terms, any non-key columns must be dependent on the entire primary key. In the case of a composite primary key, this means that a non-key column cannot depend on only part of the composite key.