# Create Table Constraint

Launch stage: GA

`POST /api/2.1/unity-catalog/constraints`

Creates a new table constraint.

 For the table constraint creation to succeed, the user must satisfy both of these conditions:
 - the user must have the **USE_CATALOG** privilege on the table's parent catalog,
   the **USE_SCHEMA** privilege on the table's parent schema, and be the owner of the table.
 - if the new constraint is a __ForeignKeyConstraint__,
   the user must have the **USE_CATALOG** privilege on the referenced parent table's catalog,
   the **USE_SCHEMA** privilege on the referenced parent table's schema,
   and be the owner of the referenced parent table.

API scopes: unity-catalog

## Request body

- `full_name_arg` (string, optional)
  The full name of the table referenced by the constraint.
- `constraint` (object, optional)
  - `primary_key_constraint` (object, required)
    - `name` (string, optional)
      The name of the constraint.
    - `child_columns` (array of string, optional)
      Column names for this constraint.
    - `timeseries_columns` (array of string, optional)
      Column names that represent a timeseries.
    - `rely` (boolean, optional)
      True if the constraint is RELY, false or unset if NORELY.
  - `foreign_key_constraint` (object, required)
    - `name` (string, optional)
      The name of the constraint.
    - `child_columns` (array of string, optional)
      Column names for this constraint.
    - `parent_table` (string, optional)
      The full name of the parent constraint.
    - `parent_columns` (array of string, optional)
      Column names for this constraint.
    - `rely` (boolean, optional)
      True if the constraint is RELY, false or unset if NORELY.
  - `named_table_constraint` (object, required)
    - `name` (string, optional)
      The name of the constraint.

## Returns

- `primary_key_constraint` (object, required)
  - `name` (string, optional)
    The name of the constraint.
  - `child_columns` (array of string, optional)
    Column names for this constraint.
  - `timeseries_columns` (array of string, optional)
    Column names that represent a timeseries.
  - `rely` (boolean, optional)
    True if the constraint is RELY, false or unset if NORELY.
- `foreign_key_constraint` (object, required)
  - `name` (string, optional)
    The name of the constraint.
  - `child_columns` (array of string, optional)
    Column names for this constraint.
  - `parent_table` (string, optional)
    The full name of the parent constraint.
  - `parent_columns` (array of string, optional)
    Column names for this constraint.
  - `rely` (boolean, optional)
    True if the constraint is RELY, false or unset if NORELY.
- `named_table_constraint` (object, required)
  - `name` (string, optional)
    The name of the constraint.

## Response

```json
{
  "primary_key_constraint": {
    "name": "string",
    "child_columns": [
      "string"
    ],
    "timeseries_columns": [
      "string"
    ],
    "rely": true
  },
  "foreign_key_constraint": {
    "name": "string",
    "child_columns": [
      "string"
    ],
    "parent_table": "string",
    "parent_columns": [
      "string"
    ],
    "rely": true
  },
  "named_table_constraint": {
    "name": "string"
  }
}
```

