# ❖ PrimaryToPrimaryKey

{% 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 **PrimaryToPrimaryKey** constraint when you have an exact 1-to-1 connection between the primary keys of two or more tables.&#x20;

{% hint style="warning" %}
***This constraint is deprecated.*** Instead of supplying a PrimaryToPrimaryKey constraint, connect primary keys in your metadata via a parent/child relationship. For more information, see the [Metadata API](/sdv/concepts/metadata/metadata-api.md).

```json
"tables": {
    "Users": {
        "primary_key": "ID",
        ...
    },
    "Supplemental Info": {
        "primary_key": "ID",
        ...
    }
},
"relationships": [{
    "parent_table_name": "Users",
    "child_table_name": "Supplemental Info",
    "parent_primary_key": "ID",
    "child_foreign_key": "ID"
}]
```

{% endhint %}

<figure><img src="/files/7tUNlHD8zKC9jAj4R0gG" alt=""><figcaption><p>In this example, the table 'Users' has an exact 1-to-1 relationship with the table 'Supplemental Info'. Both tables are connected via the same primary key ID value.</p></figcaption></figure>

## Constraint API

Create a `PrimaryToPrimaryKey` constraint

**Parameters**:&#x20;

* (required) `table_names`: A list of strings, representing the table names whose primary keys are all connected. You must provide two or more table names.

```python
from sdv.cag import PrimaryToPrimaryKey

my_constraint = PrimaryToPrimaryKey(
    table_names=['Users', 'Supplemental Info'])
```

Make sure that all the tables in you provide are in your [Metadata](/sdv/concepts/metadata.md), and have a primary key associated with them.

## 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: 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/primarytoprimarykey.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.
