> For the complete documentation index, see [llms.txt](https://vergil-lai.gitbook.io/manticoresearch-manual-zh/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://vergil-lai.gitbook.io/manticoresearch-manual-zh/emptying_a_table.md).

# • 清空表

可以使用 `TRUNCATE TABLE` SQL 语句或 PHP 客户端函数 `truncate()` 来清空表。

以下是 SQL 语句的语法：

```sql
TRUNCATE TABLE index_name [WITH RECONFIGURE]
```

执行此语句时，它会完全清空实时表（RT 表）。它会清除内存中的数据，解除所有表数据文件的链接，并释放相关的二进制日志。

也可以使用 `DELETE FROM index WHERE id>0` 来清空表，但不推荐这种方法，因为它比 `TRUNCATE` 慢。

**SQL:**

```sql
TRUNCATE TABLE products;
```

```sql
Query OK, 0 rows affected (0.02 sec)
```

**JSON:**

```http
POST /cli -d "TRUNCATE TABLE products"
```

```http
{
"total":0,
"error":"",
"warning":""
}
```

**PHP:**

```php
$params = [ 'index' => 'products' ];
$response = $client->indices()->truncate($params);
```

```php
Array(
    [total] => 0
    [error] => 
    [warning] => 
)
```

**Python:**

```python
utilsApi.sql('TRUNCATE TABLE products')
```

```python
{u'error': u'', u'total': 0, u'warning': u''}
```

**Javascript:**

```javascript
res = await utilsApi.sql('TRUNCATE TABLE products');
```

```javascript
{"total":0,"error":"","warning":""}
```

**java:**

```java
utilsApi.sql("TRUNCATE TABLE products");
```

```java
{total=0, error=, warning=}
```

**C#:**

```clike
utilsApi.Sql("TRUNCATE TABLE products");
```

```clike
{total=0, error="", warning=""}
```

此命令的一个可能用途是在[附加表](/manticoresearch-manual-zh/data_creation_and_modification/cong-wai-bu-cun-chu-tian-jia-shu-ju/cong-biao-zhong-tian-jia-shu-ju/attaching_one_table_to_another.md)之前使用。

当使用 `RECONFIGURE` 选项时，配置中指定的新标记化、词法分析和其他文本处理设置会在表被清空后生效。如果配置中的[模式声明](/manticoresearch-manual-zh/creating_a_table/data_types.md)与表模式不同，则清空表后会应用配置中的新模式。

使用此选项，清空和重新配置表将成为一个原子操作。

**SQL:**

```sql
TRUNCATE TABLE products with reconfigure;
```

```sql
Query OK, 0 rows affected (0.02 sec)
```

**JSON:**

```http
POST /cli -d "TRUNCATE TABLE products with reconfigure"
```

```http
{
"total":0,
"error":"",
"warning":""
}
```

**PHP:**

```php
$params = [ 'index' => 'products', 'with' => 'reconfigure' ];
$response = $client->indices()->truncate($params);
```

```php
Array(
    [total] => 0
    [error] => 
    [warning] => 
)
```

**Python:**

```python
utilsApi.sql('TRUNCATE TABLE products WITH RECONFIGURE')
```

```python
{u'error': u'', u'total': 0, u'warning': u''}
```

**Javascript:**

```javascript
res = await utilsApi.sql('TRUNCATE TABLE products WITH RECONFIGURE');
```

```javascript
{"total":0,"error":"","warning":""}
```

**java:**

```java
utilsApi.sql("TRUNCATE TABLE products WITH RECONFIGURE");
```

```java
{total=0, error=, warning=}
```

**C#:**

```clike
utilsApi.Sql("TRUNCATE TABLE products WITH RECONFIGURE");
```

```clike
{total=0, error="", warning=""}
```
