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

<Note>
  The \`\` 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>.
</Note>

`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/_CYD-gPJn4sApGw_/images/sql-diagrams/v25.1/truncate.svg?fit=max&auto=format&n=_CYD-gPJn4sApGw_&q=85&s=2c3a2d07beb1f2a4945b104c17df37eb" alt="truncate syntax diagram" style={{maxWidth: "100%", overflowX: "auto"}} width="577" height="157" data-path="images/sql-diagrams/v25.1/truncate.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.<br /><br />`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;
```

```
+----+------+
| 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 <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`

```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

* <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>
