CREATE TABLE LIKE
說明
CREATE TABLE
陳述式使用現有表格或檢視的定義/元資料定義新的表格。
語法
CREATE TABLE [IF NOT EXISTS] table_identifier LIKE source_table_identifier
USING data_source
[ ROW FORMAT row_format ]
[ STORED AS file_format ]
[ TBLPROPERTIES ( key1=val1, key2=val2, ... ) ]
[ LOCATION path ]
參數
-
table_identifier
指定表格名稱,可以選擇使用資料庫名稱限定。
語法:
[ database_name. ] table_name
-
USING data_source
資料來源是建立表格所使用的輸入格式。資料來源可以是 CSV、TXT、ORC、JDBC、PARQUET 等。
-
ROW FORMAT
SERDE 用於指定自訂 SerDe 或 DELIMITED 子句,以使用原生 SerDe。
-
STORED AS
表格儲存的檔案格式,可以是 TEXTFILE、ORC、PARQUET 等。
-
TBLPROPERTIES
指定必須設定的表格屬性,例如
created.by.user
、owner
等。 -
LOCATION
儲存表格資料的目錄路徑,可以是 HDFS 等分散式儲存的路徑。建立外部表格的位置。
範例
-- Create table using an existing table
CREATE TABLE Student_Dupli like Student;
-- Create table like using a data source
CREATE TABLE Student_Dupli like Student USING CSV;
-- Table is created as external table at the location specified
CREATE TABLE Student_Dupli like Student location '/root1/home';
-- Create table like using a rowformat
CREATE TABLE Student_Dupli like Student
ROW FORMAT DELIMITED FIELDS TERMINATED BY ','
STORED AS TEXTFILE
TBLPROPERTIES ('owner'='xxxx');