#### [[Normalization]] --- # Normalization > When a normalization rule has been applied to a database we can say that the database is in "[...] Normal form" ## First Normal Form (1NF) 1. Values in each cell should be atomic 1. *only 1 value in each field* 2. Tables should have no repeating groups 1. *no duplicate columns containing the same or similar data* 3. No duplicate rows in the table ## Second Normal Form (2NF) 1. For all columns in a table that are not a key, the only column they should depend on is only the whole key 1. This comes up with Composite Keys 2. ![[Pasted image 20201223164218.png]] 1. the Key is the combo of `Name` and `Date` 2. Since the Composite Key can uniquely identify each row it is a Candidate Key 3. The `Location` doesn't depend on the whole Composite Key only `Name` 1. ![[Pasted image 20201223164554.png]] 4. To make this comply with *2NF* we need a new table with the corresponding event and it's location 1. ![[Pasted image 20201223164649.png]] ## Third Normal Form (3NF) 1. We shouldn't be able to figure out any value in a column from a field that isn't a key 1. This violates *3NF* ![[Pasted image 20201223164947.png]] 2. We know that the `LunchPrice` is just half of `Price` so it is dependent on the `Price` Non-Key field. 1. this is bad when someone edits 1 column and doesnt update the price of the other 3. The fix would be to do something like define the `LunchPrice` to be what ever you want it to be but not a percentage of `Price` as that is dependence. If you classify a field that cannot be derived from a rule ("50% of [...] field") then it becomes just another non-key field # Denormalization - The process of intentionally duplicating information in a table, in violation of the normalization rules. - It is a trade-off. Gain speed, but reduce consistency --- Tags: [[Relational Databases]] - [[SQL]] - [[Database]] Reference: Related: - [[T-SQL]]