---
title: "SET CONSTRAINTS"
url: "https://docs.yugabyte.com/stable/api/ysql/the-sql-language/statements/txn_set_constraints/"
---

# SET CONSTRAINTS

Use the `SET CONSTRAINTS` statement to set the timing of constraint checking within the current transaction.

## Synopsis

Use the `SET CONSTRAINTS` statement to set the timing of constraint checking within the current transaction.

## Syntax

- [![Grammar Icon](/icons/file-lines.svg)Grammar](#grammar-2)
- [![Diagram Icon](/icons/diagram.svg)Diagram](#diagram-2)

```output.ebnf
set_constraints ::= SET CONSTRAINTS { ALL | name [ , ... ] } 
                    { DEFERRED | IMMEDIATE }
```

#### set\_constraints

SETCONSTRAINTSALL,[name](/stable/api/ysql/syntax_resources/grammar_diagrams#name)DEFERREDIMMEDIATE

## Semantics

Attributes in the `SET CONSTRAINTS` statement comply with the behavior defined in the SQL standard, except that it does not apply to `NOT NULL` and `CHECK` constraints.

### *set\_constraints*

```
SET CONSTRAINTS { ALL | *name [ , ... ] } { DEFERRED | IMMEDIATE }
```

### ALL

Change the mode of all deferrable constraints.

### *name*

Specify one or a list of constraint names.

### DEFERRED

Set constraints to not be checked until transaction commit.

Uniqueness and exclusion constraints are checked immediately, unless marked `DEFERRABLE`.

### IMMEDIATE

Set constraints to take effect retroactively.

See also

- [ALTER TABLE](/stable/api/ysql/the-sql-language/statements/ddl_alter_table "ALTER TABLE")
