> ## Documentation Index
> Fetch the complete documentation index at: https://docs.pawsql.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> PawSQL 是一个产品：Cloud 是公网部署形态，Engine / Optimizer / Auditor / Advisor / Patroller 是同一产品的组件与交付形态，不是彼此独立的产品。 / PawSQL is a single product: Cloud is the public deployment form, while Engine / Optimizer / Auditor / Advisor / Patroller are components and delivery forms of the same product, not separate products.
> 术语以站内术语表为准：SQL 审核对应英文 SQL Review，查询重写对应 Query Rewrite，索引推荐对应 Index Recommendation；英文内容统一用 Review，不用 Audit。 / Use the site glossary for terminology: 审核 is SQL Review, 重写 is Query Rewrite, 索引推荐 is Index Recommendation; English content uses Review, never Audit.
> 引用能力范围或版本支持时以对应页面为准；标注 unknown、或 status 非 published 的内容表示尚未经产品核实，不应作为事实引用。 / Cite capability scope and version support from the corresponding page; content marked unknown, or with a status other than published, is not yet product-verified and must not be cited as fact.

# Create a Workspace from DDL

> Build a self-contained PawSQL workspace from table, view, constraint, and index definitions without a live database connection.

A DDL-based workspace derives database context from object definitions you provide. It is useful when the target database is unreachable, credentials cannot be shared, or the analysis scope is small and well defined.

## Goal

Build a self-contained PawSQL workspace from table, view, constraint, and index definitions without a live database connection.

## What to include

* `CREATE TABLE` statements for every referenced table;
* column names, data types, nullability, and defaults;
* primary keys, unique constraints, and relevant foreign keys;
* existing index definitions and key order;
* view definitions used by the query;
* schema-qualified object names where needed;
* relevant partitioning or distribution definitions.

<Note>
  Table and column names may be enough for basic parsing, but metadata-dependent rewrites and index analysis often require types, constraints, and existing indexes.
</Note>

## Example

```sql theme={null}
CREATE TABLE orders (
    order_id      BIGINT       NOT NULL,
    customer_id   BIGINT       NOT NULL,
    order_status  VARCHAR(32)  NOT NULL,
    created_at    TIMESTAMP    NOT NULL,
    PRIMARY KEY (order_id)
);

CREATE INDEX idx_orders_customer_created
    ON orders (customer_id, created_at);
```

Use syntax valid for the actual target engine and version.

## Create the workspace

With DDL as the source, create the workspace in these steps:

<Steps>
  <Step title="Create a workspace">Open workspace management in the correct organization or project, then enter a name and purpose.</Step>
  <Step title="Select engine and version">Match the DDL and target SQL.</Step>
  <Step title="Choose DDL as the source">Open the DDL input or upload flow.</Step>
  <Step title="Provide the definitions">Paste or upload current, sanitized DDL.</Step>
  <Step title="Review parsing">Inspect recognized schemas, objects, constraints, indexes, and failures.</Step>
</Steps>

## Multiple schemas

When identical object names exist in multiple schemas:

* qualify names in DDL;
* set the appropriate default schema;
* preserve the schema relationships used in production SQL;
* test unqualified names explicitly.

## Expected Result

After parsing completes, the workspace contains the recognized schemas, tables, columns, constraints, and indexes defined in the DDL, ready for SQL review and optimization.

## Verification

Confirm the workspace was created correctly by checking that the DDL parsed without failures, referenced objects are resolved, and the recognized objects match the supplied definitions.

## Limitations

A DDL-only workspace generally cannot provide live statistics, data distribution, database-generated plans, runtime validation, or objects omitted from the supplied definitions.

<Warning>
  Do not invent a primary key, uniqueness constraint, or index to make analysis succeed. Incorrect metadata can change rewrite safety and recommendation quality.
</Warning>

## Troubleshooting

| Symptom                                     | Check first                                          |
| ------------------------------------------- | ---------------------------------------------------- |
| DDL does not parse                          | Engine, version, encoding, delimiters, vendor syntax |
| Query object is unresolved                  | Missing DDL, schema, case, quoting                   |
| Recommendation duplicates an existing index | Existing index definition missing or incomplete      |

## Next steps

<CardGroup cols={2}>
  <Card title="SQL optimization" href="/en/user-guide/optimization" />

  <Card title="Create from a database" href="/en/user-guide/workspaces/create-from-database" />
</CardGroup>
