> ## 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.

# TRUNCATE

The `TRUNCATE` [statement](/docs/stable/sql-statements.md) removes all rows from a table. At a high level, it works by dropping the table and recreating a new table with the same name.

> [!NOTE]
>
> The `TRUNCATE` statement performs a schema change. For more information about how online schema changes work in CockroachDB, see [Online Schema Changes](/docs/stable/online-schema-changes.md).

`TRUNCATE` is a schema change, and as such is not transactional. For more information about how schema changes work, see [Online Schema Changes](/docs/stable/online-schema-changes.md).

## Synopsis

![truncate syntax diagram](https://mintcdn.com/cockroachlabs/M6E8QStE4G5ISd4O/images/sql-diagrams/common/truncate.svg?fit=max\&auto=format\&n=M6E8QStE4G5ISd4O\&q=85\&s=3dcb8c2292fc444677b6003d7aa72c06)

## Required privileges

The user must have the `DROP` [privilege](/docs/stable/security-reference/authorization.md#managing-privileges) on the table.

## Parameters

| Parameter | Description |
| - | - |
| `table_name` | The name of the table to truncate. |
| `CASCADE` | Truncate all tables with [Foreign Key](/docs/stable/foreign-key.md) dependencies on the table being truncated. `CASCADE` does not list dependent tables it truncates, so should be used cautiously. |
| `RESTRICT` | *(Default)* Do not truncate the table if any other tables have [Foreign Key](/docs/stable/foreign-key.md) dependencies on it. |

## Viewing schema changes

This schema change statement is registered as a job.  You can view long-running jobs with [`SHOW JOBS`](/docs/stable/show-jobs).

## Examples

### Truncate a table (no foreign key dependencies)

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> SELECT * FROM t1;
```

```
+----+------+
| id | name |
+----+------+
|  1 | foo  |
|  2 | bar  |
+----+------+
(2 rows)
```

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> TRUNCATE t1;
```

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> SELECT * FROM t1;
```

```
+----+------+
| id | name |
+----+------+
+----+------+
(0 rows)
```

### Truncate a table and dependent tables

In these examples, the `orders` table has a [Foreign Key](/docs/stable/foreign-key.md) relationship to the `customers` table. Therefore, it's only possible to truncate the `customers` table while simultaneously truncating the dependent `orders` table, either using `CASCADE` or explicitly.

#### Truncate dependent tables using `CASCADE`

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> TRUNCATE customers;
```

```
pq: "customers" is referenced by foreign key from table "orders"
```

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> TRUNCATE customers CASCADE;
```

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> SELECT * FROM customers;
```

```
+----+-------+
| id | email |
+----+-------+
+----+-------+
(0 rows)
```

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> SELECT * FROM orders;
```

```
+----+----------+------------+
| id | customer | orderTotal |
+----+----------+------------+
+----+----------+------------+
(0 rows)
```

#### Truncate dependent tables explicitly

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> TRUNCATE customers, orders;
```

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> SELECT * FROM customers;
```

```
+----+-------+
| id | email |
+----+-------+
+----+-------+
(0 rows)
```

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
> SELECT * FROM orders;
```

```
+----+----------+------------+
| id | customer | orderTotal |
+----+----------+------------+
+----+----------+------------+
(0 rows)
```

## See also

* [`DELETE`](/docs/stable/delete)
* [`SHOW JOBS`](/docs/stable/show-jobs)
* [Foreign Key constraint](/docs/stable/foreign-key.md)
* [Online Schema Changes](/docs/stable/online-schema-changes.md)
