CREATE TABLE LIKE

Description

This statement is used to create an identical empty table based on the structure of another table.

Syntax:

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

Note:

  1. The replicated table structures include Column Definition, Partitions, Table Properties, etc.
  2. SELECTpermission is required on the original table.

Examples

  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