# ❖ CarryOverColumns

{% 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 **CarryOverColumns** constraint when you have the same columns in different tables, and the values of those columns have to match up according to a key (ID) column.

<figure><img src="https://1967107441-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfNxEeZzl9uFiJ4Zf4BRZ%2Fuploads%2FGk5AgJtSya7oBJ2bWnrj%2Fcarry-over-columns_May%208%202025.png?alt=media&#x26;token=995ca738-caf1-403f-8409-6782c6a14315" alt=""><figcaption><p>The 'Type' column is carried over based on the ID/Account ID information.</p></figcaption></figure>

## Constraint API

Create a `CarryOverColumns` constraint

**Parameters**:&#x20;

* (required) `common_column_info`: A list of dictionaries that describe all the columns within your dataset that are carried over. Each dictionary should have the following keys:
  * `table_name`: The name of the table that contains the column
  * `carryover_column_name`: The name of the column that is repeated across your dataset
  * `key_column_name`: The name of the column to use as the key for the carried over column. Must be a PII or ID sdtype.

Please supply 2 or more columns for this constraint.

```python
from sdv.cag import CarryOverColumns

my_constraint = CarryOverColumns(
    common_column_info=[{
        'table_name': 'Account',
        'carryover_column_name': 'Type',
        'key_column_name': 'ID'
    }, {
        'table_name': 'Transaction',
        'carryover_column_name': 'Type',
        'key_column_name': 'Account ID'
    }]
)
```

Make sure that all the tables and columns you provide are in your [Metadata](https://docs.sdv.dev/sdv/concepts/metadata).

### 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 but it is not enabled by default.

If you'd like to auto-detect this constraint specifically, you can supply it in the auto-detection parameters. This will detect all instances of the constraint throughout the dataset.

```python
constraints = synthesizer.detect_constraints(
    data,
    constraint_classes=['CarryOverColumns']
)
```

**Detection Parameters**: None
