ClickHouse/docs/en/sql-reference/statements/truncate.md

32 lines
1.5 KiB
Markdown
Raw Normal View History

2020-07-11 11:05:49 +00:00
---
2022-08-28 14:53:34 +00:00
slug: /en/sql-reference/statements/truncate
sidebar_position: 52
sidebar_label: TRUNCATE
2020-07-11 11:05:49 +00:00
---
2023-08-10 06:57:17 +00:00
# TRUNCATE Statements
2020-07-11 11:05:49 +00:00
2023-08-10 06:57:17 +00:00
## TRUNCATE TABLE
2020-07-11 11:05:49 +00:00
``` sql
TRUNCATE TABLE [IF EXISTS] [db.]name [ON CLUSTER cluster]
```
Removes all data from a table. When the clause `IF EXISTS` is omitted, the query returns an error if the table does not exist.
The `TRUNCATE` query is not supported for [View](../../engines/table-engines/special/view.md), [File](../../engines/table-engines/special/file.md), [URL](../../engines/table-engines/special/url.md), [Buffer](../../engines/table-engines/special/buffer.md) and [Null](../../engines/table-engines/special/null.md) table engines.
DOCSUP-13875: Document the replication_wait_for_inactive_replica_timeout setting (#28464) * Add documentation of settings Задокументировал две настройки. * Fix links Поправил ссылки. * Update docs/en/operations/settings/settings.md Co-authored-by: olgarev <56617294+olgarev@users.noreply.github.com> * Update docs/en/operations/settings/settings.md Co-authored-by: olgarev <56617294+olgarev@users.noreply.github.com> * Update docs/en/operations/settings/settings.md Co-authored-by: olgarev <56617294+olgarev@users.noreply.github.com> * Update docs/en/operations/settings/settings.md Co-authored-by: olgarev <56617294+olgarev@users.noreply.github.com> * Update docs/en/sql-reference/statements/alter/index.md Co-authored-by: olgarev <56617294+olgarev@users.noreply.github.com> * Update docs/en/sql-reference/statements/alter/index.md Co-authored-by: olgarev <56617294+olgarev@users.noreply.github.com> * Update docs/en/sql-reference/statements/optimize.md Co-authored-by: olgarev <56617294+olgarev@users.noreply.github.com> * Update docs/en/sql-reference/statements/truncate.md Co-authored-by: olgarev <56617294+olgarev@users.noreply.github.com> * Update docs/en/sql-reference/statements/truncate.md Co-authored-by: olgarev <56617294+olgarev@users.noreply.github.com> * Translate to Russian Выполнил перевод на русский язык. * Fix links Поправил ссылки. * Update settings.md Поправил перевод. * Update docs/en/operations/settings/settings.md Co-authored-by: olgarev <56617294+olgarev@users.noreply.github.com> * Update docs/en/sql-reference/statements/alter/index.md Co-authored-by: olgarev <56617294+olgarev@users.noreply.github.com> * Update docs/en/sql-reference/statements/optimize.md Co-authored-by: olgarev <56617294+olgarev@users.noreply.github.com> * Update docs/en/sql-reference/statements/truncate.md Co-authored-by: olgarev <56617294+olgarev@users.noreply.github.com> * Update docs/ru/operations/settings/settings.md Co-authored-by: olgarev <56617294+olgarev@users.noreply.github.com> * Update docs/ru/operations/settings/settings.md Co-authored-by: olgarev <56617294+olgarev@users.noreply.github.com> * Update docs/en/operations/settings/settings.md Co-authored-by: olgarev <56617294+olgarev@users.noreply.github.com> * Fix errors Исправил неточности в описании. * Update optimize.md Поправил описание запроса OPTIMIZE. Co-authored-by: Dmitriy <sevirov@yandex-team.ru> Co-authored-by: olgarev <56617294+olgarev@users.noreply.github.com>
2021-09-09 20:33:08 +00:00
2023-02-03 18:19:12 +00:00
You can use the [alter_sync](../../operations/settings/settings.md#alter-sync) setting to set up waiting for actions to be executed on replicas.
DOCSUP-13875: Document the replication_wait_for_inactive_replica_timeout setting (#28464) * Add documentation of settings Задокументировал две настройки. * Fix links Поправил ссылки. * Update docs/en/operations/settings/settings.md Co-authored-by: olgarev <56617294+olgarev@users.noreply.github.com> * Update docs/en/operations/settings/settings.md Co-authored-by: olgarev <56617294+olgarev@users.noreply.github.com> * Update docs/en/operations/settings/settings.md Co-authored-by: olgarev <56617294+olgarev@users.noreply.github.com> * Update docs/en/operations/settings/settings.md Co-authored-by: olgarev <56617294+olgarev@users.noreply.github.com> * Update docs/en/sql-reference/statements/alter/index.md Co-authored-by: olgarev <56617294+olgarev@users.noreply.github.com> * Update docs/en/sql-reference/statements/alter/index.md Co-authored-by: olgarev <56617294+olgarev@users.noreply.github.com> * Update docs/en/sql-reference/statements/optimize.md Co-authored-by: olgarev <56617294+olgarev@users.noreply.github.com> * Update docs/en/sql-reference/statements/truncate.md Co-authored-by: olgarev <56617294+olgarev@users.noreply.github.com> * Update docs/en/sql-reference/statements/truncate.md Co-authored-by: olgarev <56617294+olgarev@users.noreply.github.com> * Translate to Russian Выполнил перевод на русский язык. * Fix links Поправил ссылки. * Update settings.md Поправил перевод. * Update docs/en/operations/settings/settings.md Co-authored-by: olgarev <56617294+olgarev@users.noreply.github.com> * Update docs/en/sql-reference/statements/alter/index.md Co-authored-by: olgarev <56617294+olgarev@users.noreply.github.com> * Update docs/en/sql-reference/statements/optimize.md Co-authored-by: olgarev <56617294+olgarev@users.noreply.github.com> * Update docs/en/sql-reference/statements/truncate.md Co-authored-by: olgarev <56617294+olgarev@users.noreply.github.com> * Update docs/ru/operations/settings/settings.md Co-authored-by: olgarev <56617294+olgarev@users.noreply.github.com> * Update docs/ru/operations/settings/settings.md Co-authored-by: olgarev <56617294+olgarev@users.noreply.github.com> * Update docs/en/operations/settings/settings.md Co-authored-by: olgarev <56617294+olgarev@users.noreply.github.com> * Fix errors Исправил неточности в описании. * Update optimize.md Поправил описание запроса OPTIMIZE. Co-authored-by: Dmitriy <sevirov@yandex-team.ru> Co-authored-by: olgarev <56617294+olgarev@users.noreply.github.com>
2021-09-09 20:33:08 +00:00
You can specify how long (in seconds) to wait for inactive replicas to execute `TRUNCATE` queries with the [replication_wait_for_inactive_replica_timeout](../../operations/settings/settings.md#replication-wait-for-inactive-replica-timeout) setting.
:::note
2023-02-03 18:19:12 +00:00
If the `alter_sync` is set to `2` and some replicas are not active for more than the time, specified by the `replication_wait_for_inactive_replica_timeout` setting, then an exception `UNFINISHED` is thrown.
:::
2023-08-10 06:57:17 +00:00
## TRUNCATE DATABASE
``` sql
TRUNCATE DATABASE [IF EXISTS] [db.]name [ON CLUSTER cluster]
2023-08-10 06:57:17 +00:00
```
Removes all tables from a database but keeps the database itself. When the clause `IF EXISTS` is omitted, the query returns an error if the database does not exist.