Updated on 2026-11-06 GMT+08:00

Show Create Table

Function

Return the `CREATE TABLE` statement for the corresponding table. SHOW CREATE TABLE is used to view the complete definition statement of a table.

  • By default, the DataSource format CREATE TABLE statement is returned.
  • Using the AS SERDE clause returns the Hive format CREATE TABLE statement, suitable for Hive SerDe tables.

Syntax

SHOW CREATE TABLE [ db_name. ] table_name [ AS SERDE ]

Parameters

Parameter

Mandatory

Description

db_name

No

Database name. If not specified, the current database is used by default.

table_name

Yes

Table name. The specified table must exist. Otherwise, an error will occur.

AS SERDE

No

Used to generate a Hive SerDe format CREATE TABLE statement, suitable for tables using Hive storage format. If not specified, the DataSource format CREATE TABLE statement is generated by default.

Precautions

  • The specified table must exist. Otherwise, an error will occur.
  • Without AS SERDE, the DataSource format CREATE TABLE statement is returned (recommended).
  • With AS SERDE, the Hive SerDe format CREATE TABLE statement is returned, including Hive-specific properties such as ROW FORMAT SERDE, INPUTFORMAT, OUTPUTFORMAT.

Example 1: Show Create Table Statement

View the CREATE TABLE statement for the employee table.

SHOW CREATE TABLE employee;

Example result (DataSource format):

+--------------------+
|createtab_stmt      |
+--------------------+
|CREATE TABLE employee (
  id INT,
  name STRING,
  salary DOUBLE)
USING parquet
TBLPROPERTIES (
  'transient_lastDdlTime' = '1718534400')
+--------------------+

Example 2: View the Create Table Statement for a DataSource Table

Create a DataSource format table and view its CREATE TABLE statement.

-- Create a DataSource format table.
CREATE TABLE sales (order_id INT, amount DOUBLE, order_date DATE)
  USING parquet
  LOCATION 'obs://my-bucket/warehouse/sales';

-- View the Create Table statement.
SHOW CREATE TABLE sales;

Example 3: View the Create Table Statement for a Hive Format Table (AS SERDE)

Use AS SERDE to view the Hive format CREATE TABLE statement.

-- Create a Hive format table.
CREATE TABLE logs (id INT, message STRING)
  ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe'
  STORED AS TEXTFILE;

-- View the CREATE TABLE statement in Hive SerDe format.
SHOW CREATE TABLE logs AS SERDE;

Example result (Hive SerDe format):

+--------------------+
|createtab_stmt      |
+--------------------+
|CREATE TABLE logs (
  id INT,
  message STRING)
ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe'
STORED AS
  INPUTFORMAT 'org.apache.hadoop.mapred.TextInputFormat'
  OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
TBLPROPERTIES (
  'serialization.format' = '1',
  'transient_lastDdlTime' = '1718534400')
+--------------------+

Example 4: View the Create Table Statement for a Table in a Specified Database

View the CREATE TABLE statement for the employee table in the company_db database.

SHOW CREATE TABLE company_db.employee;