Normalization
Normalization
redundancy and improve data integrity. There are several normal forms (1NF, 2NF, 3NF,
etc.) to achieve normalization. Here’s a step-by-step guide to normalize a database in
MySQL:
Example Scenario
Let's consider a database for a library with the following unnormalized table Books:
In the example:
PublisherName and PublisherAddress only depend on Publisher, not on the Book.
We split the table into two: Books and Publishers.
New Tables:
CREATE TABLE Publishers (
PublisherID INT PRIMARY KEY AUTO_INCREMENT,
PublisherName VARCHAR(100),
PublisherAddress VARCHAR(255)
);
In the Books table, AuthorCountry depends on AuthorName, not on the primary key BookID.
Therefore, we split the author details into a separate table.
Example:
SELECT Books.BookTitle, Authors.AuthorName, Publishers.PublisherName
FROM Books
JOIN Authors ON Books.AuthorID = Authors.AuthorID
JOIN Publishers ON Books.PublisherID = Publishers.PublisherID;
Conclusion:
By following the steps above, you can achieve database normalization in MySQL, which
helps in improving data integrity, minimizing redundancy, and organizing your database
efficiently.