SHOW CREATE TABLE

Berlaku untuk:centang ditandai ya Databricks SQL centang ditandai ya Databricks Runtime

Catatan

Untuk menggunakan perintah ini pada tampilan materialisasi atau tabel streaming, Anda harus menggunakan Databricks Runtime versi 14.1 atau lebih tinggi.

Mengembalikan pernyataan yang digunakan untuk membuat tabel atau tampilan tertentu. Pernyataan yang dikembalikan dapat berupa salah satu jenis berikut:

SHOW CREATE TABLE pada tampilan sementara atau tabel yang tidak ada memberikan pengecualian.

Sintaks

SHOW CREATE TABLE { table_name | view_name }

Parameter-parameternya

Contoh

> CREATE TABLE test (c INT) ROW FORMAT DELIMITED FIELDS TERMINATED BY ','
    STORED AS TEXTFILE
    TBLPROPERTIES ('prop1' = 'value1', 'prop2' = 'value2');

> SHOW CREATE TABLE test;
                                       createtab_stmt
 ----------------------------------------------------
 CREATE TABLE `default`.`test` (`c` INT)
 USING text
 TBLPROPERTIES (
   'transient_lastDdlTime' = '1586269021',
   'prop1' = 'value1',
   'prop2' = 'value2')

Contoh berikut menunjukkan SHOW CREATE TABLE tampilan metrik. Output mengambil definisi asli dan ALTER VIEW perubahan berikutnya, dan nama tampilan dikembalikan sebagai nama tiga bagian yang sepenuhnya memenuhi syarat.

> CREATE OR REPLACE VIEW sample_sales_metrics_v2
    COMMENT 'Sales metrics for product and regional analysis'
    TBLPROPERTIES ('created_by' = 'Evan')
    WITH METRICS
    LANGUAGE YAML
    AS $$
  version: 1.1
  source: sample_sales
  comment: "Sales metrics for product and regional analysis"

  dimensions:
    - name: product_category
      expr: product_category
      comment: "Category of the product sold"
    - name: region
      expr: region
  measures:
    - name: total_sales
      expr: SUM(sales_amount)
      comment: "Sum of all sales amounts"
    - name: total_quantity
      expr: SUM(quantity)
      comment: "Total number of items sold"
  $$;

> ALTER VIEW sample_sales_metrics_v2
    SET TBLPROPERTIES ('purpose' = 'For testing');

> SHOW CREATE TABLE sample_sales_metrics_v2;
                              createtab_stmt
 ------------------------------------------------------------
 CREATE VIEW main.default.sample_sales_metrics_v2 (
   product_category COMMENT 'Category of the product sold',
   region,
   total_sales COMMENT 'Sum of all sales amounts',
   total_quantity COMMENT 'Total number of items sold')
 COMMENT 'Sales metrics for product and regional analysis'
 TBLPROPERTIES (
   'created_by' = 'Evan',
   'purpose' = 'For testing')
 WITH METRICS
 LANGUAGE YAML
 AS
 $$
 version: 1.1

 source: sample_sales

 comment: Sales metrics for product and regional analysis

 dimensions:
   - name: product_category
     expr: product_category
     comment: Category of the product sold
   - name: region
     expr: region

 measures:
   - name: total_sales
     expr: SUM(sales_amount)
     comment: Sum of all sales amounts
   - name: total_quantity
     expr: SUM(quantity)
     comment: Total number of items sold
 $$