# Normalization and Denormalization in Databases

**What is Normalization?** Normalization is a method used in organizing data inside a database. It breaks down big tables into smaller, simpler tables and links them. This method helps avoid duplicate data and ensures that all data is stored clearly and logically. By doing this, databases can work better because they don't have unnecessary or repeated information.

**Benefits of Normalization:**

* **Clearer Data**: Data is organized more clearly, which helps in managing and using the data effectively.
    
* **Avoids Problems**: Reduces problems like data being wrong or missing when you add, delete, or change data.
    
* **Saves Space**: It uses the storage space more efficiently.
    

**What is Denormalization?** Denormalization is a technique used to speed up how fast you can get data from a database. It does this by allowing some duplicate data. By combining tables and adding duplicate data, databases can find information faster, which is useful when you need to get a lot of data quickly.

**Benefits of Denormalization:**

* **Faster Data Access**: This helps you get data faster, which is useful for reports or analysis that need quick access to large amounts of information.
    
* **Simpler Queries**: This makes writing database queries simpler because data that needs to be accessed together is kept together.
    

**When to Use Each:**

* **Normalization** is usually better when you need to make sure your data is very accurate and stored efficiently, like in systems where data is constantly being added or changed.
    
* **Denormalization** might be better in situations where you need to read data a lot and fast, like in systems that generate reports or handle lots of searches.
    

# Example

## Denormalized "Students" Table Structure

| StudentID | Name | Email | Password | Section | Subjects | Professors | GWA | IsActive | LsEnrolled | IsSuspended | Address | Phone | BirthDate | EmergencyContact | RegistrationDate | AdvisorName |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| 1 | John Doe | johndoe@example.com | pass1234 | A1 | Math, Science | Dr. Smith, Prof. Lee | 3.5 | true | 2023-08 | false | 123 Elm St | 123-456-7890 | 2000-01-01 | 123-456-7891 | 2020-08-01 | Dr. Allen |
| 2 | Jane Smith | janes@example.com | pass5678 | A2 | English, History | Prof. Kent, Dr. Jones | 3.7 | true | 2023-08 | false | 456 Maple Ave | 234-567-8901 | 1999-02-15 | 234-567-8902 | 2019-09-01 | Prof. Carter |
| 3 | Alice Johnson | alicej@example.com | pass91011 | A1 | Science, PE | Dr. Smith, Coach Ray | 3.8 | false | 2023-08 | true | 789 Oak Blvd | 345-678-9012 | 2001-03-30 | 345-678-9013 | 2021-01-15 | Dr. Harris |
| 4 | Bob Brown | bobb@example.com | pass1213 | A2 | Math, English | Dr. Lee, Prof. Kent | 3.2 | true | 2023-08 | false | 321 Pine Rd | 456-789-0123 | 2000-05-25 | 456-789-0124 | 2022-07-10 | Prof. Sanders |
| 5 | Carol White | carolw@example.com | pass1415 | A1 | History, Science | Dr. Jones, Dr. Smith | 3.9 | true | 2023-08 | false | 654 Spruce Ln | 567-890-1234 | 1998-07-09 | 567-890-1235 | 2018-08-20 | Dr. Murphy |
| 6 | Dave Green | daveg@example.com | pass1617 | A2 | PE, Math | Coach Ray, Dr. Lee | 2.9 | false | 2023-08 | true | 987 Cedar St | 678-901-2345 | 2002-09-17 | 678-901-2346 | 2023-01-05 | Prof. Thompson |
| 7 | Eva Black | evab@example.com | pass1819 | A1 | English, PE | Prof. Kent, Coach Ray | 3.6 | true | 2023-08 | false | 321 Birch St | 789-012-3456 | 2001-11-23 | 789-012-3457 | 2022-06-15 | Dr. Allen |
| 8 | Frank Gray | frankg@example.com | pass2021 | A2 | History, Math | Dr. Jones, Dr. Lee | 3.1 | true | 2023-08 | false | 213 Willow Rd | 890-123-4567 | 1997-12-31 | 890-123-4568 | 2017-09-25 | Prof. Carter |
| 9 | Grace Hill | graceh@example.com | pass2223 | A1 | Science, History | Dr. Smith, Dr. Jones | 4.0 | false | 2023-08 | true | 132 Elm St | 901-234-5678 | 2002-02-20 | 901-234-5679 | 2021-10-30 | Dr. Harris |
| 10 | Henry Lake | henryl@example.com | pass2425 | A2 | English, PE | Prof. Kent, Coach Ray | 2.8 | true | 2023-08 | false | 312 Maple Ave | 012-345-6789 | 1999-04-05 | 012-345-6790 | 2019-12-05 | Prof. Sanders |

---

## Normalization Table Structure

### `1. Students Table`

| StudentID | Name | Email | Password | BirthDate | IsActive | LsEnrolled | IsSuspended |
| --- | --- | --- | --- | --- | --- | --- | --- |
| 1 | John Doe | [johndoe@example.com](mailto:johndoe@example.com) | pass1234 | 2000-01-01 | true | 2023-08 | false |
| 2 | Jane Smith | [janes@example.com](mailto:janes@example.com) | pass5678 | 1999-02-15 | true | 2023-08 | false |
| ... | ... | ... | ... | ... | ... | ... | ... |

---

`2. Address Table`

| AddressID | StudentID | Address | Phone | EmergencyContact |
| --- | --- | --- | --- | --- |
| 1 | 1 | 123 Elm St | 123-456-7890 | 123-456-7891 |
| 2 | 2 | 456 Maple Ave | 234-567-8901 | 234-567-8902 |
| ... | ... | ... | ... | ... |

`3. Subjects Table`

| SubjectID | Name |
| --- | --- |
| 1 | Math |
| 2 | Science |
| ... | ... |

4. `Enrollments Table`
    

### 5\. Professors Table

| ProfessorID | Name |
| --- | --- |
| 1 | Dr. Smith |
| 2 | Prof. Lee |
| ... | ... |

### 6\. Advisors Table

Stores advisor information and links them to students.

| AdvisorID | ProfessorID |
| --- | --- |
| 1 | 1 |
| 2 | 2 |
| ... | ... |

### 7\. Registrations Table

| RegistrationID | StudentID | RegistrationDate | AdvisorID |
| --- | --- | --- | --- |
| 1 | 1 | 2020-08-01 | 1 |
| 2 | 2 | 2019-09-01 | 2 |
| ... | ... | ... | ... |

### Normalization Benefits:

* **Reduces Redundancy**: Each piece of information exists only once in the database.
    
* **Improves Data Integrity**: Updates have to be made in only one place, reducing the risk of inconsistent data.
    
* **Enhances Security**: Can apply security measures to individual tables. For example, limiting access to the password table.
    

This normalized model minimizes redundancy by ensuring that each data element is stored only once. Relationships among the data are maintained through foreign keys

### References:  
GeeksforGeeks.

Difference between Normalization and Denormalization (tutorialspoint.com)

Normalization in SQL (1NF - 5NF): A Beginner’s Guide | DataC[amp](https://www.datacamp.com/tutorial/normalization-in-sql)
