Files
doris/docs/en/sql-reference/sql-statements/Data Definition/CREATE TABLE LIKE.md
WangCong 28f4e922a7 [CREATE TABLE]Support new syntax CREATE TABLE LIKE to clone an existe… (#4705)
Support new synatx CREATE TABLE [IF NOT EXISTS] [db_name].table_name AS [db_name2].table_name2;
to create a new table from existed table with same table schema.
ISSUE: #4355
2020-10-10 21:16:53 +08:00

1.9 KiB

title, language
title language
CREATE TABLE LIKE en

CREATE TABLE LIKE

description

Use CREATE TABLE ... LIKE to create an empty table based on the definition of another table, including any column attributes, table partitions and table properties defined in the original table: Syntax:

    CREATE [EXTERNAL] TABLE [IF NOT EXISTS] [database.]table_name LIKE [database.]table_name

Explain: 1. The replicated table structures include Column Defination, Partitions, Table Properties, and so on 2. The SELECT privilege is required on the original table. 3. Support to copy external table such as MySQL.

Example

1. Under the test1 Database, create an empty table with the same table structure as table1, named table2

    CREATE TABLE test1.table2 LIKE test1.table1

2. Under the test2 Database, create an empty table with the same table structure as test1.table1, named table2

    CREATE TABLE test2.table2 LIKE test1.table1

3. Under the test1 Database, create an empty table with the same table structure as MySQL's external table1, called table2

    CREATE TABLE test1.table2 LIKE test1.table1

keyword

    CREATE,TABLE,LIKE