# export sql

> Export a data contract to SQL DDL.

# `datacontract export sql`

{/* AUTOGENERATED from `datacontract --help`: do not edit by hand; regenerate with update_command_docs.py */}

Export a data contract to SQL DDL.

```bash
datacontract export sql [OPTIONS] [LOCATION]
```

| Argument | Default | Description |
|---|---|---|
| `[LOCATION]` | `datacontract.yaml` | The location (url or path) of the data contract yaml. |

| Option | Default | Description |
|---|---|---|
| `--dialect` | `auto` | The SQL dialect. Use `auto` (default) to detect the SQL dialect via the specified servers in the data contract. |
| `--output` | — | File path where the exported data will be saved. If not provided, it will be printed to stdout. |
| `--server` | — | The server name to export. |
| `--schema-name` | `all` | Which schema to export, e.g., `orders`, or `all` for all schemas (default). |
| `--json-schema` | — | The location (url or path) of the ODCS JSON Schema. |
| `--inline-references` / `--no-inline-references` | `--inline-references` | Resolve external references (currently: authoritativeDefinitions\[type in \{definition, semantics\}]) in the contract and inline the fetched content from the configured entropy-data host. |
| `--clickhouse-engine` | — | The ClickHouse table engine. Default: MergeTree(). Example: ReplicatedMergeTree('/clickhouse/tables/\{shard\}/table', '\{replica\}') |
| `--clickhouse-order-by` | — | ORDER BY columns for ClickHouse (comma-separated). ClickHouse uses ORDER BY as its primary/sorting key (not PRIMARY KEY). Default: primary key columns if defined, omitted otherwise. Example: --clickhouse-order-by "event_date DESC, event_id" |
| `--debug` / `--no-debug` | — | Enable debug logging |

```bash
datacontract export sql datacontract.yaml --dialect postgres --output ddl.sql
```

Guide: **[Export: SQL DDL](../../exports/sql.md)**.
