Junior — Middle
How is data structured according to the third normal form of a database?
sobes.tech AI
Answer from AI
The Third Normal Form (3NF) requires that data in the database be organized so that:
- The table is in the Second Normal Form (2NF).
- All non-key attributes depend only on the primary key, not on other non-key attributes (absence of transitive dependencies).
In simpler terms, in 3NF, each column should depend directly on the table's key, not through another column. This reduces redundancy and increases data integrity.
For example, if you have a table with orders that stores both customer information and order details, it is better to move the customer data to a separate table to avoid duplication in each order.
Example structure:
-- Customers table
CREATE TABLE Customers (
CustomerID INT PRIMARY KEY,
Name VARCHAR(100),
Email VARCHAR(100)
);
-- Orders table
CREATE TABLE Orders (
OrderID INT PRIMARY KEY,
CustomerID INT,
OrderDate DATE,
FOREIGN KEY (CustomerID) REFERENCES Customers(CustomerID)
);
Here, customer information is stored separately, and orders only contain a reference to the customer, which complies with 3NF.