Skip to content

Commit 9191b23

Browse files
authored
docs: alter table (#10885)
* Update 90-alter-table-column.md * Update 90-alter-table-column.md * Update 90-alter-table-column.md
1 parent ec4f1ea commit 9191b23

File tree

1 file changed

+36
-17
lines changed

1 file changed

+36
-17
lines changed
Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
---
2-
title: ALTER Table Column
2+
title: ALTER TABLE
33
description:
4-
Add or drop column of a table.
4+
Adds or drops a column of a table.
55
---
66

7-
Add or drop column of a table.
7+
Adds or drops a column of a table.
8+
9+
:::tip
10+
ALTER TABLE can also handle table clustering. For more information, refer to the following pages:
11+
12+
- [ALTER CLUSTER KEY](../70-clusterkey/dml-alter-cluster-key.md)
13+
- [RECLUSTER TABLE](../70-clusterkey/dml-recluster-table.md)
14+
:::
815

916
## Syntax
1017

@@ -16,18 +23,30 @@ ALTER TABLE [IF EXISTS] <name> DROP COLUMN <column_name>
1623
## Examples
1724

1825
```sql
19-
-- Create table
20-
CREATE TABLE t(a int, b float);
21-
INSERT INTO t VALUES(1,2);
22-
23-
-- Add a column
24-
ALTER TABLE t ADD COLUMN c float DEFAULT 10;
25-
-- Should return `1 2 10.0`
26-
SELECT * FROM t;
27-
28-
-- Drop a column
29-
ALTER TABLE t DROP COLUMN b;
30-
-- Should return `1 10.0`
31-
SELECT * FROM t;
32-
26+
DESC books;
27+
28+
Field |Type |Null|Default |Extra|
29+
--------+---------+----+------------+-----+
30+
price |FLOAT |NO |0.00 | |
31+
pub_time|TIMESTAMP|NO |'1900-01-01'| |
32+
author |VARCHAR |NO |"" | |
33+
34+
ALTER TABLE books ADD COLUMN region varchar;
35+
DESC books;
36+
37+
Field |Type |Null|Default |Extra|
38+
--------+---------+----+------------+-----+
39+
price |FLOAT |NO |0.00 | |
40+
pub_time|TIMESTAMP|NO |'1900-01-01'| |
41+
author |VARCHAR |NO |"" | |
42+
region |VARCHAR |NO |"" | |
43+
44+
ALTER TABLE books DROP COLUMN region;
45+
DESC books;
46+
47+
Field |Type |Null|Default |Extra|
48+
--------+---------+----+------------+-----+
49+
price |FLOAT |NO |0.00 | |
50+
pub_time|TIMESTAMP|NO |'1900-01-01'| |
51+
author |VARCHAR |NO |"" | |
3352
```

0 commit comments

Comments
 (0)