> For the complete documentation index, see [llms.txt](https://docs.sdv.dev/sdv/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.sdv.dev/sdv/modeling/constraint-augmented-generation-cag/predefined-constraints/uniquebridgetable.md).

# ❖ UniqueBridgeTable

{% 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 **UniqueBridgeTable** constraint when you have a bridge table that records a many-to-many relationship between multiple tables, and the connections have to be unique. That is to say, the combinations of keys in the bridge tables must be unique.

{% hint style="warning" %}
***This constraint is deprecated.*** Instead of supplying a UniqueBridgeTable constraint, represesent the bridge table as a composite key in your metadata. For more information, see the [Metadata API](/sdv/integration/metadata/metadata-api.md).

```json
{
    "tables": {
        "Authors": {
            "primary_key": "ID",
            ...
        },
        "Books": {
            "primary_key": "ID",
            ...
        },
        "Author-Book": {
            "primary_key": ["Author ID", "Book ID"],
            ...
        }
    },
    "relationships": [{
        "parent_table_name": "Authors",
        "parent_primary_key": "ID",
        "child_table_name": "Author-Book",
        "child_foreign_key": "Author ID",
    },{
        "parent_table_name": "Books",
        "parent_primary_key": "ID",
        "child_table_name": "Author-Book",
        "child_foreign_key": "Book ID", 
    }]   
}
```

{% endhint %}

<figure><img src="/files/vnGoYpqJOWVPdRV11iv2" alt=""><figcaption><p>The Author-Book table records unique links between Authors and Books.</p></figcaption></figure>

## Constraint API

Create a `UniqueBridgeTable` constraint.

**Parameters**:&#x20;

* (required) `table_name`: A string with the name of the bridge table
* (required) `foreign_key_columns`: A list of strings with the names of the foreign key columns. The combination of values in these columns must be unique.

```python
from sdv.cag import UniqueBridgeTable

my_constraint = UniqueBridgeTable(
    table_name='Author-Book',
    foreign_key_columns=['Author ID', 'Book ID'])
```

Make sure that all the tables and columns you provide are listed in your [Metadata](/sdv/integration/metadata.md), as well as all foreign key connections.

## 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).


---

# 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 dynamically by asking a question.

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

```
GET https://docs.sdv.dev/sdv/modeling/constraint-augmented-generation-cag/predefined-constraints/uniquebridgetable.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
