Skip to content

Commit afc3f29

Browse files
authored
Update 10-ddl-create-table.md (#10856)
1 parent d308b57 commit afc3f29

File tree

1 file changed

+54
-7
lines changed

1 file changed

+54
-7
lines changed

docs/doc/14-sql-commands/00-ddl/20-table/10-ddl-create-table.md

Lines changed: 54 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@ For detailed information about the CLUSTER BY clause, see [SET CLUSTER KEY](../7
5858

5959
## CREATE TABLE ... LIKE
6060

61-
Creates an empty copy of an existing table, the new table automatically copies all column names, their data types, and their not-null constraints.
61+
Creates a table with the same column definitions as an existing table. Column names, data types, and their non-NUll constraints of the existing will be copied to the new table.
62+
63+
- This command does NOT copy any data from the existing table.
64+
- This command does NOT copy attributes of the existing table, such as `TRANSIENT` and `CLUSTER BY`, and creates the new table with system defaults. Some table attributes can be added using [ALTER TABLE](90-alter-table-column.md), for example, CLUSTER BY. See an example in [Examples](#create-table--like-1).
6265

6366
Syntax:
6467
```sql
@@ -264,11 +267,11 @@ SELECT * FROM test;
264267

265268
### Create Table ... Like
266269

270+
The following example indicates that the command does not copy any data from an existing table but only the column definitions:
271+
267272
```sql
268273
CREATE TABLE test2 LIKE test;
269-
```
270274

271-
```sql
272275
DESC test2;
273276
+-------+--------+------+---------------+
274277
| Field | Type | Null | Default |
@@ -277,13 +280,10 @@ DESC test2;
277280
| b | String | NO | |
278281
| c | String | NO | concat(b, -b) |
279282
+-------+--------+------+---------------+
280-
```
281283

282-
```sql
283284
INSERT INTO test2(a,b) VALUES(888, 'stars');
284-
```
285285

286-
```sql
286+
-- The new table contains inserted data only. Data in the existing table was not copied.
287287
SELECT * FROM test2;
288288
+------+-------+---------+
289289
| a | b | c |
@@ -292,6 +292,53 @@ SELECT * FROM test2;
292292
+------+-------+---------+
293293
```
294294

295+
The following example indicates that the command does not copy attributes of an existing table:
296+
297+
```sql
298+
CREATE TRANSIENT TABLE tb_01(id int, c1 varchar) CLUSTER BY(id);
299+
300+
SET hide_options_in_show_create_table=0
301+
302+
SHOW CREATE TABLE tb_01;
303+
304+
Table|Create Table |
305+
-----+---------------------------------------------------------------------------------------------------------------------------------------+
306+
tb_01|CREATE TABLE `tb_01``id` INT`c1` VARCHAR¶) ENGINE=FUSE CLUSTER BY (id) TRANSIENT='T' COMPRESSION='lz4' STORAGE_FORMAT='native'|
307+
308+
309+
CREATE TABLE tb_02 LIKE tb_01;
310+
311+
-- The attributes CLUSTER BY and TRANSIENT were not copied to the new table.
312+
313+
SHOW CREATE TABLE tb_02;
314+
315+
Table|Create Table |
316+
-----+---------------------------------------------------------------------------------------------------------+
317+
tb_02|CREATE TABLE `tb_02``id` INT`c1` VARCHAR¶) ENGINE=FUSE COMPRESSION='lz4' STORAGE_FORMAT='native'|
318+
319+
-- Add CLUSTER BY using ALTER TABLE.
320+
321+
ALTER TABLE tb_02 CLUSTER BY(id);
322+
323+
Table|Create Table |
324+
-----+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
325+
tb_02|CREATE TABLE `tb_02``id` INT`c1` VARCHAR¶) ENGINE=FUSE CLUSTER BY (id) COMPRESSION='lz4' SNAPSHOT_LOCATION='1/21465/_ss/6b4b16900a4c4134b7dab535b1c93546_v2.json' STORAGE_FORMAT='native'|
326+
327+
-- Not all the table attributes can be added using ALTER TABLE. See the ALTER TABLE page for which attributes can be changed.
328+
329+
ALTER TABLE tb_02 TRANSIENT='T';
330+
331+
SQL Error [1105] [HY000]: Code: 1005, displayText = error:
332+
--> SQL:1:83
333+
|
334+
1 | /* ApplicationName=DBeaver 23.0.1 - SQLEditor <Script-1.sql> */ alter table tb_02 TRANSIENT='T'
335+
| ----- ^^^^^^^^^ expected `RENAME`, `ADD`, `DROP`, `CLUSTER`, `RECLUSTER`, `FLASHBACK`, or 1 more ...
336+
| |
337+
| while parsing `ALTER TABLE [<database>.]<table> <action>`
338+
339+
.
340+
```
341+
295342
### Create Table ... As
296343

297344
```sql

0 commit comments

Comments
 (0)