SCRIPT TABLE AS CREATE

Generates a complete CREATE DELTA TABLE DDL script from an existing table's metadata, including column definitions, constraints, partitioning, clustering, table properties, and comments.

Category: utilityDeltaForge extension

Syntax

SCRIPT TABLE <table> AS CREATE

Description

## Overview SCRIPT TABLE AS CREATE reads an existing Delta table's metadata and produces the CREATE DELTA TABLE DDL statement that would recreate an identical table. This is the reverse-engineering counterpart to DESCRIBE TABLE, producing executable DDL rather than a tabular schema listing. ## Behavior The engine opens the Delta table, reads its latest snapshot, and extracts all structural metadata: 1. **Column Definitions**: Each column's name, data type (converted from Arrow notation to Delta SQL type names), nullability (NOT NULL constraints), and comment (from field metadata). 2. **Partition Columns**: Columns specified in PARTITIONED BY are listed separately and excluded from the main column list. 3. **Clustering Columns**: If liquid clustering is configured (via delta.clusteringColumns table property), the CLUSTER BY clause is included. 4. **Table Properties**: All configuration properties stored in the Delta metadata (excluding internal clustering properties) are included in the TBLPROPERTIES clause. 5. **Table Comment**: The table description, if set, is included as a COMMENT clause. The generated DDL is formatted using the default format options and returned as a single-row result set with one column: **ddl_script**. ### Type Mapping Arrow data types are mapped back to Delta SQL types: | Arrow Type | Delta SQL Type | |------------|----------------| | Boolean | BOOLEAN | | Int8 | TINYINT | | Int16 | SMALLINT | | Int32 | INT | | Int64 | BIGINT | | Float32 | FLOAT | | Float64 | DOUBLE | | Utf8 | STRING | | Date32 | DATE | | Timestamp | TIMESTAMP | | Binary | BINARY | | Decimal128 | DECIMAL(p, s) | Nested types (Struct, List, Map) are serialized with their full type signatures. The generated DDL does not include the LOCATION clause, since the storage path is environment-specific and should be specified at deployment time. ## Compatibility SCRIPT TABLE AS CREATE is a DeltaForge extension inspired by SQL Server Management Studio's "Script Table as CREATE" feature. The generated DDL uses DeltaForge CREATE DELTA TABLE syntax and is directly executable.

Parameters

NameTypeDescription
tableSpecifies the name or path of the existing Delta table to reverse-engineer. The table must be registered in the session via CREATE DELTA TABLE or OPEN DELTA TABLE. Fully qualified names (zone.schema.table) are supported.

Examples

-- Generate DDL for a table
SCRIPT TABLE warehouse.sales.orders AS CREATE;
-- Reverse-engineer a partitioned table
SCRIPT TABLE gold.analytics.daily_revenue AS CREATE;
-- Generate DDL for schema migration documentation
SCRIPT TABLE staging.import.raw_events AS CREATE;

Pitfalls

See Also

Open in interactive docs →   DeltaForge home →