# ❖ 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](https://docs.sdv.dev/sdv/explore/sdv-bundles/cag) 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](https://docs.sdv.dev/sdv/concepts/metadata/metadata-api).

```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="https://1967107441-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfNxEeZzl9uFiJ4Zf4BRZ%2Fuploads%2FeMnrC63ULCD1vkGPnvEw%2Funique-bridge-table_May%208%202025.png?alt=media&#x26;token=80f0e5c3-ad64-4b65-991f-10a1ea061686" 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](https://docs.sdv.dev/sdv/concepts/metadata), 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).
