You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/doc/14-sql-commands/00-ddl/20-table/10-ddl-create-table.md
+54-7Lines changed: 54 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -58,7 +58,10 @@ For detailed information about the CLUSTER BY clause, see [SET CLUSTER KEY](../7
58
58
59
59
## CREATE TABLE ... LIKE
60
60
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).
62
65
63
66
Syntax:
64
67
```sql
@@ -264,11 +267,11 @@ SELECT * FROM test;
264
267
265
268
### Create Table ... Like
266
269
270
+
The following example indicates that the command does not copy any data from an existing table but only the column definitions:
271
+
267
272
```sql
268
273
CREATETABLEtest2LIKE test;
269
-
```
270
274
271
-
```sql
272
275
DESC test2;
273
276
+-------+--------+------+---------------+
274
277
| Field | Type | Null | Default |
@@ -277,13 +280,10 @@ DESC test2;
277
280
| b | String | NO | |
278
281
| c | String | NO | concat(b, -b) |
279
282
+-------+--------+------+---------------+
280
-
```
281
283
282
-
```sql
283
284
INSERT INTO test2(a,b) VALUES(888, 'stars');
284
-
```
285
285
286
-
```sql
286
+
-- The new table contains inserted data only. Data in the existing table was not copied.
287
287
SELECT*FROM test2;
288
288
+------+-------+---------+
289
289
| a | b | c |
@@ -292,6 +292,53 @@ SELECT * FROM test2;
292
292
+------+-------+---------+
293
293
```
294
294
295
+
The following example indicates that the command does not copy attributes of an existing table:
0 commit comments