> For the complete documentation index, see [llms.txt](https://codexpress.gitbook.io/welcome-to-datagenesis/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://codexpress.gitbook.io/welcome-to-datagenesis/normalisation/2-normal-form.md).

# 2 Normal Form

The Second Normal Form (2NF) is a concept in database normalization that builds upon the First Normal Form (1NF). It addresses issues related to partial dependencies in a relational database. To be in 2NF, a table must satisfy the following conditions:

1. It must already be in 1NF, which means that it contains only atomic values (no repeating groups or arrays in columns).
2. It should not have partial dependencies, which occur when non-key attributes (attributes not part of the primary key) depend on only part of a candidate key.

In simpler terms, 2NF eliminates redundancy and ensures that all non-key attributes are functionally dependent on the entire primary key, not just part of it.

Here's an example to illustrate 2NF:

Consider a table called `Orders` with the following attributes:

| OrderID | ProductID | ProductName | CustomerID | CustomerName | Quantity |
| ------- | --------- | ----------- | ---------- | ------------ | -------- |
| 1       | 101       | Laptop      | 1001       | Alice        | 2        |
| 2       | 102       | Smartphone  | 1002       | Bob          | 3        |
| 3       | 101       | Laptop      | 1003       | Carol        | 1        |

In this table:

* `OrderID` is the primary key.
* `ProductID` is part of the candidate key because it identifies a product within an order.
* `CustomerID` is also part of the candidate key because it identifies a customer associated with an order.
* `ProductName` is functionally dependent on `ProductID`.
* `CustomerName` is functionally dependent on `CustomerID`.
* `Quantity` is functionally dependent on both `OrderID` and `ProductID` because it represents the quantity of a specific product in a specific order.

However, there's a problem related to partial dependency. The `Quantity` attribute depends on `ProductID`, which is only part of the candidate key. This violates the 2NF because non-key attributes should depend on the entire candidate key.

To bring this table into 2NF, you should split it into two separate tables: one for orders and another for order details. Here's how it might look in 2NF:

**Table: Orders**

| OrderID | CustomerID |
| ------- | ---------- |
| 1       | 1001       |
| 2       | 1002       |
| 3       | 1003       |

**Table: OrderDetails**

| OrderID | ProductID | Quantity |
| ------- | --------- | -------- |
| 1       | 101       | 2        |
| 2       | 102       | 3        |
| 3       | 101       | 1        |

In this revised structure, each table adheres to 2NF. The `Quantity` attribute now depends on the entire primary key (composite key of `OrderID` and `ProductID`). This eliminates partial dependencies and reduces data redundancy, making the database more efficient and easier to manage.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://codexpress.gitbook.io/welcome-to-datagenesis/normalisation/2-normal-form.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
