
# ALTER TABLE修改表结构
本章节主要介绍ClickHouse修改表结构的SQL基本语法和使用说明。
#### 基本语法
**ALTER TABLE** \[*database_name* \].*name* \[**ON CLUSTER** *cluster* \] **ADD** \|**DROP** \|**CLEAR** \|**COMMENT** \|**MODIFY** **COLUMN**...
![](https://support.huaweicloud.com/cmpntguide-mrs/public_sys-resources/note_3.0-zh-cn.png)
ALTER仅支持 \*MergeTree ，Merge以及Distributed等引擎表。
#### 使用示例
```
--给表t1增加列test01 
ALTER TABLE t1 ADD COLUMN test01 String DEFAULT 'defaultvalue';
--查询修改后的表t1
desc t1
┌─name────┬─type─┬─default_type─┬─default_expression ┬─comment─┬─codec_expression─┬─ttl_expression─┐
│  id          │ UInt8  │                │                     │           │                    │                  │  
│  name        │ String │                │                     │           │                    │                  │ 
│  address     │ String │                │                     │           │                    │                  │
│  test01      │ String │  DEFAULT       │  'defaultvalue'     │           │                    │                  │
└───────┴────┴────────┴────────── ┴───── ┴──────────┴─────────┘
--修改表t1列name类型为UInt8
ALTER TABLE t1 MODIFY COLUMN name UInt8;
--查询修改后的表t1
desc t1
┌─name────┬─type─┬─default_type─┬─default_expression ┬─comment─┬─codec_expression─┬─ttl_expression─┐
│  id          │ UInt8  │                │                     │           │                    │                  │  
│  name        │ UInt8  │                │                     │           │                    │                  │ 
│  address     │ String │                │                     │           │                    │                  │
│  test01      │ String │  DEFAULT       │  'defaultvalue'     │           │                    │                  │
└───────┴────┴────────┴────────── ┴───── ┴──────────┴─────────┘
--删除表t1的列test01
ALTER TABLE t1 DROP COLUMN test01;
--查询修改后的表t1
desc t1
┌─name────┬─type─┬─default_type─┬─default_expression ┬─comment─┬─codec_expression─┬─ttl_expression─┐
│  id          │ UInt8  │                │                     │           │                    │                  │  
│  name        │ UInt8  │                │                     │           │                    │                  │ 
│  address     │ String │                │                     │           │                    │                  │
└───────┴────┴────────┴────────── ┴───── ┴──────────┴─────────┘
```
