# View tables and views in a database

View tables and views in a database. Use the returned object name to view fields, table information, or table creation statements.

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

## Preparation before calling

Prepare your personal access token, workspace ID, and database name. You can first [query database](list-databases.md) to confirm the name.

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

## 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>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 to be queried.</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/db/table" \
  -H "X-API-Key: $AI_STUDIO_API_KEY" \
  -H "X-Workspace-ID: $WORKSPACE_ID" \
  -H 'Content-Type: application/json' \
  -d "{\"name\":\"$DATABASE\"}"
```
:::
::::
## Successful response

```json
{
  "code": 200,
  "data": {
    "db_name": "sales",
    "tables": {"tables": [{"name": "orders", "owner": "", "created": "", "rows": 0, "size": 0}], "total": 1},
    "views": {"tables": [], "total": 0}
  }
}
```

The response fields are as follows.


| Field | Type | Description |
| --- | --- | --- |
| `code` | integer | `200` on success. |
| `data.db_name` | string | The name of the database being queried. |
| `data.tables.tables` | array of object or null | Table list. The service may return `null` when there are no tables; treat this as an empty list. |
| `data.views.tables` | array of object or null | View list. The service may return `null` when there are no views; treat this as an empty list. |
| `data.tables.total` | integer | Number of objects in the table list. |
| `data.views.total` | integer | Number of objects in the view list. |
| `data.tables.tables[].name` | string | Table name; used to query table information, fields or table creation statements. |
| `data.views.tables[].name` | string | View name; used to view table creation statements or delete views. |
| `data.tables.tables[].owner` | string | Table object owner. |
| `data.views.tables[].owner` | string | View object owner. |
| `data.tables.tables[].created` | string | Table object creation time. |
| `data.views.tables[].created` | string | View object creation time. |
| `data.tables.tables[].rows` | integer | Number of table object rows. |
| `data.views.tables[].rows` | integer | Number of view object rows. |
| `data.tables.tables[].size` | integer | Table object size. |
| `data.views.tables[].size` | integer | View object size. |

In field paths, `[]` denotes each item in an array. For example, `items[].name` is the `name` field of each item in the `items` array.


## 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": 400,
  "message": "name 不能为空"
}
```
:::
::::
## Follow-up operations

Save the identification of the target item, and then [query table information](get-table-info.md).
