# Manage Catalogs, Databases, and Tables

Prepare a catalog and database by name within a workspace, create a table, and read its rows. Completing this returns a table resource on which subsequent reads, previews, truncations, or deletions are executed.

(sdk-ai-studio-catalog-table-flow)=
## Task workflow

1. The caller provides workspace, catalog name, database name, table name, and column definitions.
2. The SDK searches for matching catalogs and databases in the workspace, creating them if not found.
3. The SDK creates the table inside that database and returns the corresponding table resource.
4. Use the returned table resource to read table data.

(sdk-ai-studio-catalog-table-prepare)=
## Prerequisites

| Required item | Role on this page |
| --- | --- |
| Authenticated client and selected workspace | Determine the scope of this resource operation. |
| Catalog, database, and table names | Select or create target resource locations. |
| Column definitions | Construct table schema. |
| Creation permissions | Allow provisioning non-existent resources in the target location. |

This page does not create clients or select workspaces. Complete the initial connection in Quickstart first, then pass the bound workspace to the following example.

(sdk-ai-studio-catalog-table-create)=
## Create a table

The following function prepares a catalog and database in an existing workspace, then creates a table. Preparing by name is not a read-only lookup: missing resources will trigger creation operations.

:::::{tab-set}
:sync-group: sdk-language

::::{tab-item} Python
:sync: python

```python
import moi_product_sdk as sdk


def create_orders_table(workspace):
    catalog = workspace.prepare_catalog("analytics")
    database = catalog.prepare_database("sales")
    table, _ = database.create_table_from_columns(
        "orders",
        [
            sdk.TableColumn("order_id", "INT"),
            sdk.TableColumn("customer_name", "VARCHAR"),
        ],
    )
    return table
```

::::

::::{tab-item} Go
:sync: go

```go
import (
	"context"

	sdk "github.com/matrixorigin/matrixflow/sdk/go-sdk"
)

func createOrdersTable(ctx context.Context, workspace *sdk.WorkspaceHandle) (*sdk.TableHandle, error) {
	catalog, err := workspace.PrepareCatalog(ctx, "analytics")
	if err != nil {
		return nil, err
	}
	database, err := catalog.PrepareDatabase(ctx, "sales")
	if err != nil {
		return nil, err
	}
	table, _, err := database.CreateTable(ctx, "orders", []sdk.TableColumn{
		{Name: "order_id", Type: "INT"},
		{Name: "customer_name", Type: "VARCHAR"},
	})
	if err != nil {
		return nil, err
	}
	return table, nil
}
```

::::

:::::

(sdk-ai-studio-catalog-table-read)=
## Read table data

The table resource returned by the creation function can be used directly to read data. The following code only reads currently returned rows; it does not guarantee that subsequent writes, imports, or queries have completed.

:::::{tab-set}
:sync-group: sdk-language

::::{tab-item} Python
:sync: python

```python
rows = table.data()
```

::::

::::{tab-item} Go
:sync: go

```go
rows, err := table.Data(ctx)
if err != nil {
	return err
}
_ = rows
```

::::

:::::

(sdk-ai-studio-catalog-table-result)=
## Result confirmation

Retain the table resource returned by the creation function, or reacquire it using explicitly provided resource identifiers from creation, listing, or caller inputs. Read results confirm only this retrieval; imports, queries, and writes should be verified via their respective task statuses.

(sdk-ai-studio-catalog-table-limit)=
## Limitations

- Table names and column schemas must be provided by the caller; the SDK does not infer table structure from file names or display titles.
- Dropping or truncating tables modifies data. Confirm the target workspace, catalog, database, and table before proceeding.

(sdk-ai-studio-catalog-table-next)=
## Next steps

- [Manage volumes and files](管理卷和文件.md)
- [Create data transmission tasks](../数据连接/创建导入导出任务.md)
