# View table or view creation statement

View the create statement for the table or view. The response contains the object definition and does not contain the data from the table.

```text
POST https://moi.matrixorigin.cn/newmoi/meta/table/ddl
```

## Preparation before calling

Prepare the personal access token, workspace ID, database name, and object name. You can first [query the table in the database](list-database-tables.md) to confirm the table or view name.

The examples below use `$AI_STUDIO_API_KEY`, `$WORKSPACE_ID`, `$DATABASE`, and `$TABLE`.

## Request body

Replace caller-specific values in the example with actual values.

::::{div} mo-api-split
:::{div} mo-api-split-main
```{raw} html
<dl class="mo-api-fields">
<div class="mo-api-field"><dt><code>db_name</code><span class="mo-api-field__type">string</span><span class="mo-api-field__required">Required</span></dt><dd>The name of the database where the table or view resides.</dd></div>
<div class="mo-api-field"><dt><code>table_name</code><span class="mo-api-field__type">string</span><span class="mo-api-field__required">Required</span></dt><dd>The name of the table or view to read DDL from.</dd></div>
</dl>
```
:::
:::{div} mo-api-split-aside
```{raw} html
<p class="mo-api-example-label">Request example</p>
```
```bash
curl -X POST "https://moi.matrixorigin.cn/newmoi/meta/table/ddl" \
  -H "X-API-Key: $AI_STUDIO_API_KEY" \
  -H "X-Workspace-ID: $WORKSPACE_ID" \
  -H 'Content-Type: application/json' \
  -d "{\"db_name\":\"$DATABASE\",\"table_name\":\"$TABLE\"}"
```
:::
::::
## Successful response

```json
{"code":200,"data":{"create_sql":"CREATE TABLE orders (id INT PRIMARY KEY)"}}
```

The response fields are as follows.

| Field | Type | Description |
| --- | --- | --- |
| `code` | integer | `200` on success. |
| `data.create_sql` | string | The `CREATE TABLE` statement for a table, or the `CREATE VIEW` statement for a view. |

## Error response

::::{div} mo-api-split
:::{div} mo-api-split-main
```{raw} html
<dl class="mo-api-fields">
<div class="mo-api-field"><dt><code>code</code><span class="mo-api-field__type">integer or string</span></dt><dd>Error code or status.</dd></div>
<div class="mo-api-field"><dt><code>message</code><span class="mo-api-field__type">string</span></dt><dd>Error message.</dd></div>
</dl>
```
:::
:::{div} mo-api-split-aside
```{raw} html
<p class="mo-api-example-label">Error response example</p>
```
```json
{
  "code": 404,
  "message": "对象不存在"
}
```
:::
::::
## Follow-up operations

[View table column list](list-table-columns.md) when returning to the list.
