> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cockroachlabs.com/llms.txt
> Use this file to discover all available pages before exploring further.

# NOT NULL constraint

The `NOT NULL` [constraint](/docs/stable/constraints.md) specifies a column may not contain [`NULL`](/docs/stable/null-handling) values.

## Details

* `INSERT` or `UPDATE` statements containing `NULL` values are rejected. This includes `INSERT` statements that do not include values for any columns that do not have a [`DEFAULT` value constraint](/docs/stable/default-value).

  For example, if the table `foo` has columns `a` and `b` (and `b` *does not* have a `DEFAULT VALUE`), when you run the following command:

  ```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
  > INSERT INTO foo (a) VALUES (1);
  ```

  CockroachDB tries to write a `NULL` value into column `b`. If that column has the `NOT NULL` constraint, the `INSERT` statement is rejected.

* To add the `NOT NULL` constraint to an existing table column, use the [`ALTER COLUMN`](/docs/stable/alter-table#set-not-null-constraint) statement.

* For more information about `NULL`, see [NULL handling](/docs/stable/null-handling.md).

## Syntax

You can only apply the `NOT NULL` constraint to individual columns.

![not\_null\_column\_level syntax diagram](https://mintcdn.com/cockroachlabs/UZNSFbmU2EwEm6G5/images/sql-diagrams/common/not_null_column_level.svg?fit=max\&auto=format\&n=UZNSFbmU2EwEm6G5\&q=85\&s=6432afe5ef94de03626cf1a1df8518fd)

| Parameter | Description |
| - | - |
| `table_name` | The name of the table you're creating. |
| `column_name` | The name of the constrained column. |
| `column_type` | The constrained column's [data type](/docs/stable/data-types.md). |
| `column_constraints` | Any other column-level [constraints](/docs/stable/constraints.md) you want to apply to this column. |
| `column_def` | Definitions for any other columns in the table. |
| `table_constraints` | Any table-level [constraints](/docs/stable/constraints.md) you want to apply. |

## Usage example

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> CREATE TABLE IF NOT EXISTS customers (
    customer_id INT         PRIMARY KEY,
    cust_name   STRING(30)  NULL,
    cust_email  STRING(100) NOT NULL
  );
```

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> INSERT INTO customers (customer_id, cust_name, cust_email) VALUES (1, 'Smith', NULL);
```

```
pq: null value in column "cust_email" violates not-null constraint
```

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> INSERT INTO customers (customer_id, cust_name) VALUES (1, 'Smith');
```

```
pq: null value in column "cust_email" violates not-null constraint
```

## See also

* [Constraints](/docs/stable/constraints.md)
* [`DROP CONSTRAINT`](/docs/stable/alter-table#drop-constraint)
* [`CHECK` constraint](/docs/stable/check)
* [`DEFAULT` constraint](/docs/stable/default-value)
* [`REFERENCES` constraint (Foreign Key)](/docs/stable/foreign-key)
* [`PRIMARY KEY` constraint](/docs/stable/primary-key)
* [`UNIQUE` constraint](/docs/stable/unique)
* [`SHOW CONSTRAINTS`](/docs/stable/show-constraints)
* [`NULL HANDLING`](/docs/stable/null-handling)
