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

# TRUNCATE

export const InternalLink = ({version, path = "", children, ...props}) => {
  let detectedVersion = version || "stable";
  if (typeof window !== 'undefined' && !version) {
    const match = window.location.pathname.match(/\/docs\/([^/]+)/);
    if (match) {
      detectedVersion = match[1];
    }
  }
  const normalizedPath = path.startsWith("/") ? path.slice(1) : path;
  return <a href={`/docs/${detectedVersion}/${normalizedPath}`} {...props}>
      {children}
    </a>;
};

The `TRUNCATE` <InternalLink path="sql-statements">statement</InternalLink> 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.

The `TRUNCATE` statement performs a schema change. For more information about how online schema changes work in CockroachDB, see <InternalLink path="online-schema-changes">Online Schema Changes</InternalLink>.

`TRUNCATE` is a schema change, and as such is not transactional. For more information about how schema changes work, see <InternalLink path="online-schema-changes">Online Schema Changes</InternalLink>.

## Synopsis

<img src="https://mintcdn.com/cockroachlabs/2sY29RlbaeZjvP07/images/sql-diagrams/v25.4/truncate.svg?fit=max&auto=format&n=2sY29RlbaeZjvP07&q=85&s=1f7a485dfa432e240ba9b3f00e19113a" alt="truncate syntax diagram" style={{maxWidth: "100%", overflowX: "auto"}} width="577" height="157" data-path="images/sql-diagrams/v25.4/truncate.svg" />

<img src="https://mintcdn.com/cockroachlabs/bALSwIJ7kkDMfVP4/images/generated/docs/v25.4/truncate/syntax-diagram-67a5256005c8.svg?fit=max&auto=format&n=bALSwIJ7kkDMfVP4&q=85&s=4314b8a26133a0f5b088b85df65114c2" alt="SQL syntax diagram" width="577" height="157" data-path="images/generated/docs/v25.4/truncate/syntax-diagram-67a5256005c8.svg" />

## Required privileges

The user must have the `DROP` <InternalLink path="security-reference/authorization#managing-privileges">privilege</InternalLink> on the table.

## Parameters

| Parameter     | Description                                                                                                                                                                                                           |
| ------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `table\_name` | The name of the table to truncate.                                                                                                                                                                                    |
| `CASCADE`     | Truncate all tables with <InternalLink path="foreign-key">Foreign Key</InternalLink> 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 <InternalLink path="foreign-key">Foreign Key</InternalLink> dependencies on it.                                                                        |

## Viewing schema changes

This schema change statement is registered as a job. You can view long-running jobs with <InternalLink path="show-jobs">`SHOW JOBS`</InternalLink>.

## Examples

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

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

```text theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
+----+------+
| 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;
```

```text theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
+----+------+
| id | name |
+----+------+
+----+------+
(0 rows)
```

### Truncate a table and dependent tables

In these examples, the `orders` table has a <InternalLink path="foreign-key">Foreign Key</InternalLink> 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`

`CASCADE` truncates *all* dependent tables without listing them, which can lead to inadvertent and difficult-to-recover losses. To avoid potential harm, we recommend truncating tables explicitly in most cases. See [Truncate Dependent Tables Explicitly](#truncate-dependent-tables-explicitly) for more details.

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

```text theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
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;
```

```text theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
+----+-------+

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

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

```text theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
+----+----------+------------+
| 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;
```

```text theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
+----+-------+
| id | email |
+----+-------+
+----+-------+
(0 rows)
```

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

```text theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
+----+----------+------------+
| id | customer | orderTotal |
+----+----------+------------+
+----+----------+------------+
(0 rows)
```

## See also

* <InternalLink path="delete">`DELETE`</InternalLink>
* <InternalLink path="show-jobs">`SHOW JOBS`</InternalLink>
* <InternalLink path="foreign-key">Foreign Key constraint</InternalLink>
* <InternalLink path="online-schema-changes">Online Schema Changes</InternalLink>
