# ❖ DenormalizedTable

{% hint style="info" %}
❖ **SDV Enterprise Bundle**. This feature is available as part of the **CAG Bundle**, an optional add-on to SDV Enterprise. For more information, please visit the [CAG Bundle](/sdv/explore/sdv-bundles/cag.md) page.
{% endhint %}

Use the **DenormalizedTable** constraint when you have a table that was created by denormalizing a parent and child table. This happens when you collapse a parent table into the child by repeating its values.

<figure><img src="/files/DgdGTfFsO9CA8v4uPMkM" alt=""><figcaption><p>In this example, the <code>Transactions-Users</code> table is a denormalized table that contains information about transactions and users. One user can have many transactions. Users have been collapsed into the table by repeating the User ID and Birthday.</p></figcaption></figure>

## Constraint API

Create a `DenormalizedTable` constraint

**Parameters**:&#x20;

* (required) `table_name`: A string containing the name of the denormalized table
* (required) `denormalized_primary_key`: A string containing the name of the column that represents the primary key of the denormalized, parent table. The values in this column are likely repeated as part of the denormalization process.
* (required) `denormalized_column_names`: A list of strings containing the column names that were also a part of the denormalized, parent table. The values in these columns are also likely repeated. They should be consistent for every denormalized primary key value.

```python
from sdv.cag import DenormalizedTable

my_constraint = DenormalizedTable(
    table_name='Transactions-Users',
    denormalized_primary_key='User ID',
    denormalized_column_names=['User Birthdate']
)
```

Make sure that the table and column names you provide are in your [Metadata](/sdv/concepts/metadata.md). The denormalized table may be part of a broader, multi-table dataset.

## Usage

Apply the constraint to any SDV synthesizer. Then fit and sample as usual.

```python
synthesizer = HSASynthesizer(metadata)
synthesizer.add_constraints([my_constraint])

synthesizer.fit(data)
synthetic_data = synthesizer.sample()
```

For more information about using predefined constraints, please see the [**Constraint-Augmented Generation tutorial**](https://colab.research.google.com/drive/1WCMQujfVKL5giULZXOPPIBoMfzR9Zj68?usp=sharing).

## Auto-Detection

Auto-detection is allowed for this constraint and it is enabled by default for multi-table datasets. Run the detection with your data to detect all instances of this constraint throughout the dataset.

```python
constraints = synthesizer.detect_constraints(data)
```

**Detection Parameters**: None


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.sdv.dev/sdv/concepts/constraint-augmented-generation-cag/predefined-constraints/denormalizedtable.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
