Database Table by Name

https://{your-workspace-slug}.{region}.xata.sh/db/db_branch_name/tables/table_name

This endpoint provides a way to mutate a specific table on a database.

Expected parameters

NameDescriptionInRequiredSchema
db_branch_name

The DBBranchName matches the pattern {db_name}:{branch_name}.

pathstring
table_name

The Table name

pathstring

Create Table

PUT
https://{your-workspace-slug}.{region}.xata.sh/db/db_branch_name/tables/table_name

Creates a new table with the given name. Returns 422 if a table with the same name already exists.

Responses

{
    "branchName": "mydb_main",
    "tableName": "mytable",
    "status": "completed"
}

Delete Table

DELETE
https://{your-workspace-slug}.{region}.xata.sh/db/db_branch_name/tables/table_name

Deletes the table with the given name.

Responses

type DeleteTable = {
    status: MigrationStatus;
};
 
type MigrationStatus = "completed" | "pending" | "failed";

Update Table

PATCH
https://{your-workspace-slug}.{region}.xata.sh/db/db_branch_name/tables/table_name

Update table. Currently there is only one update operation supported: renaming the table by providing a new name.

In the example below, we rename a table from “users” to “people”:

// PATCH /db/test:main/tables/users
 
{
  "name": "people"
}

Request Body Type Definition

type UpdateTable = {
    /**
     * @minLength 1
     */
    name: string;
};

Responses

type UpdateTable = {
    /**
     * @minLength 1
     */
    migrationID: string;
    parentMigrationID: string;
    status: MigrationStatus;
};
 
type MigrationStatus = "completed" | "pending" | "failed";