CREATE TABLE LIKE (SQL Analytics)CREATE TABLE LIKE (SQL Analytics)

定义一个使用现有表或视图的定义和元数据的表。Defines a table using the definition and metadata of an existing table or view.

Delta Lake 不支持 CREATE TABLE LIKEDelta Lake does not support CREATE TABLE LIKE. 请改用 CREATE TABLE ASInstead use CREATE TABLE AS. 请参阅 ASSee AS.

语法Syntax

CREATE TABLE [ IF NOT EXISTS ] table_identifier LIKE source_table_identifier
    USING data_source
    [ TBLPROPERTIES ( key1=val1, key2=val2, ... ) ]
    LOCATION path

参数Parameters

  • table_identifiertable_identifier

    表名,可选择使用数据库名称进行限定。A table name, optionally qualified with a database name.

    语法: [database_name.] table_nameSyntax: [database_name.] table_name

  • USING data_sourceUSING data_source

    将要用于表的文件格式。The file format to use for the table. data_source 必须是 TEXTCSVJSONJDBCPARQUETORC 之一。data_source must be one of TEXT, CSV, JSON, JDBC, PARQUET, or ORC. 另外还必须指定 LOCATIONYou must also specify LOCATION.

  • TBLPROPERTIESTBLPROPERTIES

    用于标记表定义的键值对列表。A list of key-value pairs used to tag the table definition.

  • LOCATIONLOCATION

    用于存储表数据的目录路径,可以是分布式存储上的一个路径。Path to the directory where table data is stored, which could be a path on distributed storage. 创建外部表的位置。Location to create an external table.

示例Examples

-- Create table using a new location
CREATE TABLE Student_Dupli LIKE Student LOCATION '/mnt/data_files';

-- Create table like using a data source
CREATE TABLE Student_Dupli LIKE Student USING CSV LOCATION '/mnt/csv_files';