What is normalization in MySQL

Normalization in MySQL is the process of organizing data in a database to minimize redundancy and dependency. The primary goals are to separate data into different tables and ensure relationships between those tables to efficiently manage and retrieve information.

There are several normal forms that one can apply during the normalization process, including:

  • First Normal Form (1NF): Ensures that all values in a table are atomic, meaning each column contains indivisible values.
  • Second Normal Form (2NF): Requires that a table is in 1NF and all non-key attributes are fully functionally dependent on the primary key.
  • Third Normal Form (3NF): Demands that a table is in 2NF and that all the attributes are dependent only on the primary key.

Here's an example of how normalization works in MySQL:

-- Original Table: Employee CREATE TABLE Employee ( EmployeeID INT PRIMARY KEY, EmployeeName VARCHAR(50), Department VARCHAR(50), DepartmentLocation VARCHAR(50) ); -- Normalized Tables CREATE TABLE Department ( DepartmentID INT PRIMARY KEY, DepartmentName VARCHAR(50), DepartmentLocation VARCHAR(50) ); CREATE TABLE Employee ( EmployeeID INT PRIMARY KEY, EmployeeName VARCHAR(50), DepartmentID INT, FOREIGN KEY (DepartmentID) REFERENCES Department(DepartmentID) );

MySQL normalization database normalization database design SQL relational database