# Structure

The Structure tab shows a table's columns, keys, indexes, constraints, triggers and definition. Changes to columns, indexes and keys wait as pending changes until you preview and commit them, the same way row edits do.

## Where to find it

| Action | How |
| --- | --- |
| Open a table's structure | `Structure` at the bottom of a table tab, `⌘⌃]` (`Ctrl+Alt+]`), `View` > `Structure`, or `Open Structure` in the table's sidebar context menu |
| Return to the rows | `Data`, or `⌘⌃[` (`Ctrl+Alt+[`) |
| Create a table or view | The `Create object` button above the sidebar catalog, then `New table...` or `New view...` |
| Rename, truncate or drop a table | `Rename...`, `Truncate...` or `Drop...` in the table's sidebar context menu |
| Read the definition | `Definition` in the structure header |
| Preview pending changes | `Preview`, or `⌘⇧P` (`Ctrl+Shift+P`) |
| Commit pending changes | `Commit`, or `⌘S` (`Ctrl+S`) |

## Reading a table's structure

The header shows the schema and table name, a kind badge such as `Table`, an estimated row count and the table's size. Below it, `Columns`, `Primary key`, `Indexes`, `Foreign keys`, `Constraints` and `Triggers` each have a heading with a count. The columns grid lists each column's name, type, nullability, default, identity or generated attribute, comment and key roles, and on MySQL it adds unsigned, collation, on update, generated and auto increment details. Expand an index, foreign key, constraint or trigger to read its full definition.

![The orders table in the Structure tab: the header with its row estimate and size, and the columns grid listing id, customer_id, status, placed_at, placed_unix, total, shipping_address and updated_at with their types, nullability and defaults.](https://bobbytables.app/docs/img/structure/01-columns.png)

_Columns come first, followed by the key, index, constraint and trigger sections._

![The Indexes section of orders listing the primary key index and orders_placed_at_idx on placed_at, and the Triggers section listing orders_updated_at.](https://bobbytables.app/docs/img/structure/02-indexes-triggers.png)

_Each index shows its columns and properties, and each trigger shows when it fires and what it runs._

## Changing columns

`Column` above the grid adds a column, and so does `⌘I` (`Ctrl+I`). Double-click a cell or press `Enter` to edit a name, type or default, and select columns and choose `Drop` to mark them for removal. Each change is highlighted, and the bar above the tab counts them, for example `3 changes`, next to `Discard`, `Preview` and `Commit`. `Preview` opens `SQL preview` with the exact `ALTER TABLE` statements, and `Index` and `Foreign key` in their section headings add to the same set of changes.

[In the orders Structure tab, a column named notes with type text is added to the columns grid, its default is changed, and Preview opens the SQL preview showing the ALTER TABLE statements.](https://bobbytables.app/docs/video/structure/03-add-column.mp4)

_New and changed columns stay pending until you preview and commit them._

## Creating tables and views

`New table...` opens `New table`, where each column gets a name, type, default, nullability and primary key choice, and `Preview` shows the `CREATE TABLE` statement before you choose `Create table`. `New view...` opens `New view` with a name, a query editor and a `Statement preview`, and `Create view` runs it. Both run as soon as you confirm, without waiting in the pending changes.

## Renaming, truncating and dropping

`Rename...` shows the rename statement for the new name and runs it when you choose `Rename`. `Truncate...` and `Drop...` always open a confirmation that names the table and shows the `Exact statement`, whatever the safe mode setting. On PostgreSQL the confirmation adds `CASCADE`, truncate also adds `RESTART IDENTITY`, and the statement changes as you tick them. On a connection tagged Production you also type the table name before `Truncate` or `Drop` is available.

![The truncate confirmation for a table, with This removes every row immediately., the exact TRUNCATE statement, and RESTART IDENTITY and CASCADE checkboxes.](https://bobbytables.app/docs/img/structure/07-truncate-confirmation.png)

_Truncate confirms every time, even with safe mode off._

## Definition

`Definition` in the structure header opens the table's full definition in a side panel, and `Copy` puts it on the clipboard. On MySQL and MariaDB the panel is titled `SHOW CREATE`.

## Good to know

- PostgreSQL, CockroachDB, SQL Server and SQLite commit structure changes in one transaction.
- MySQL, MariaDB, TiDB, Oracle, ClickHouse and Snowflake cannot roll back DDL. `Commit` opens the preview first, with a warning that earlier statements stay applied if a later one fails, and the create, rename, truncate and drop dialogs show the same warning.
- On SQLite, changing a column other than renaming it, adding or removing a key or constraint, or dropping a column that belongs to a key or index rebuilds the table, and the preview says `This change rebuilds the table`.
- With [safe mode](https://bobbytables.app/docs/safe-mode) on, creating, renaming and committing structure changes also ask before they run.
- On a read-only connection the editing controls are disabled and explain `Connection is read-only`.
- Cloudflare D1 does not support graphical structure changes. Run DDL in the SQL editor instead.
- The [schema diagram](https://bobbytables.app/docs/schema-diagram) draws the same keys across tables. Native workspaces such as [MongoDB](https://bobbytables.app/docs/mongodb) and [Redis](https://bobbytables.app/docs/redis) have no Structure tab.

## Related

- [Table data](https://bobbytables.app/docs/table-data.md)
- [Schema diagram](https://bobbytables.app/docs/schema-diagram.md)
- [Database snapshots](https://bobbytables.app/docs/snapshots.md)
- [Editing rows](https://bobbytables.app/docs/editing.md)
