Skip to main content
CREATE TABLE LIKE creates an identical empty table based on the definition of another table. The definition includes column definition, partitions, and table properties. You can copy an external table such as MySQL. v3.2 allows you to specify a different partitioning method, bucketing method, and properties for the new table than the source table. Tip This operation requires the CREATE TABLE privilege on the database in which you want to create a table, and the SELECT privilege on the source table based on which to create a table.

Syntax

  • Syntax supported in versions earlier than v3.2.
  • v3.2 supports specifying properties for the new table.

Parameters

  • TEMPORARY: Creates a temporary table. From v3.3.1, the database supports creating temporary tables in the Default Catalog. For more information, see Temporary Table.
  • database: the database.
  • table_name: the name of the table you want to create. For the naming conventions, see System limits.
  • source_table_name: the name of the source table you want to copy.
    • partition_desc: the partitioning method. For more information, see CREATE TABLE.
  • distribution_desc: the bucketing method. For more information, see CREATE TABLE.
  • PROPERTIES: the properties of the table. All the table properties are supported. For more information, see ALTER TABLE.

Examples

Suppose there is a table orders in database test1.
Example 1: In database test1, create an empty table order_1 that has the same table structure as orders.
Example 2: Create an empty table order_2 based on orders and specify properties for order_2.
Example 3: Create an empty table table2 that has the same table structure as MySQL external table table1.