2022-01-30 06:51:56 +00:00
|
|
|
---
|
2022-08-26 19:07:59 +00:00
|
|
|
slug: /zh/sql-reference/statements/truncate
|
2022-04-10 23:08:18 +00:00
|
|
|
sidebar_position: 52
|
|
|
|
sidebar_label: TRUNCATE
|
2022-01-30 06:51:56 +00:00
|
|
|
---
|
|
|
|
|
2022-01-30 06:57:40 +00:00
|
|
|
# TRUNCATE 语句 {#truncate-statement}
|
2022-01-30 06:51:56 +00:00
|
|
|
|
|
|
|
``` sql
|
|
|
|
TRUNCATE TABLE [IF EXISTS] [db.]name [ON CLUSTER cluster]
|
|
|
|
```
|
|
|
|
|
2022-01-30 06:57:40 +00:00
|
|
|
删除表中的所有数据。当省略子句 `IF EXISTS` 时,如果表不存在,则查询返回一个错误。
|
2022-01-30 06:51:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2022-01-30 06:57:40 +00:00
|
|
|
`TRUNCATE` 查询不支持[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) 和 [Null](../../engines/table-engines/special/null.md)表引擎。
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-02-03 18:19:12 +00:00
|
|
|
可以使用 alter_sync 设置在复制集上等待执行的操作。
|
2022-01-30 06:57:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2022-01-31 11:01:47 +00:00
|
|
|
通过 replication_wait_for_inactive_replica_timeout 设置,可以指定不活动副本执行 `TRUNCATE`查询需要等待多长时间(以秒为单位)。
|
2022-01-30 06:57:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
!!! info "注意"
|
2023-02-03 18:19:12 +00:00
|
|
|
如果`alter_sync` 被设置为`2`,并且某些复制集超过 `replication_wait_for_inactive_replica_timeout`设置的时间不激活,那么将抛出一个异常`UNFINISHED`。
|