Structure & Table Actions

Change columns and indexes, preview the generated SQL, and create, rename, copy or drop tables.

Mantidb lets you change a table's columns and indexes from a grid, without writing ALTER TABLE by hand. Like data edits, structure changes stay pending until you apply them, and you can see the exact SQL first.

Structure view

Open a table and click Structure in the bottom bar. Each row is a column of the table:

ColumnDescription
#The column's position.
column_nameThe column's name.
data_typeThe declared type, such as integer or varchar(255).
is_nullableA checkbox: checked when the column Allows NULL.
defaultThe default value expression.
keyWhether the column is part of a key.

Each row also has a revert button that undoes the pending changes on that column.

Indexes view

Click Indexes in the bottom bar to list the table's indexes:

ColumnDescription
index_nameThe index's name.
columnsThe indexed columns. Click to Choose columns… for a new index.
uniqueWhether the index is unique.
primaryYES for the primary key index.
methodThe index method, such as btree.

Making changes

In the Structure view you can:

  • Add a column with + Column in the bottom bar.
  • Rename a column by editing column_name.
  • Change its type, nullability or default.
  • Drop a column.

In the Indexes view you can:

  • Create an index with + Index.
  • Drop an index.

The bottom bar shows how many changes are pending. A Pending SQL preview below the grid shows the statements Mantidb will run, updated as you edit. If a change can't be turned into SQL, the preview says Can't build the ALTER.

Primary keys, foreign keys and check constraints can't be edited from the Structure view. Change them with a query instead.

Applying changes

Press ⌘S to apply the pending changes, or click Discard to throw them away. Changes go through safe mode first, like any other write.

How the statements run depends on the engine:

EngineHow changes are applied
PostgreSQLIn one transaction. If any statement fails, nothing changes.
SQLiteIn one transaction.
SQL ServerIn one transaction.
MySQL / MariaDBStatement by statement. These engines can't roll back DDL, so changes made before an error stay applied.

If the table has pending row edits in the Data view, commit or discard them before changing its structure.

When editing is blocked

The Structure view is read-only for:

  • Views — "Only tables can be altered".
  • Amazon Redshift — "Redshift structure is read-only".
  • Connections in Read only safe mode.

Engine notes

  • SQLite can only rename, add and drop columns. Changing a column's type, nullability or default isn't supported.
  • SQL Server changes a column's type and nullability together, and drops and recreates named default constraints when you change a default.
  • MySQL / MariaDB apply changes one statement at a time, as described above.

Table actions

Right-click a table in the sidebar to manage it. Right-click empty space in the list for New Table… only.

New table

New Table… creates a table in the current schema. It starts with an id primary key column and opens in the Structure view, where you add the other columns.

Rename

Rename… asks for the new name.

Queries, views and code that use the old name stop working.

Duplicate

Duplicate… copies the table's structure under a new name (<table>_copy by default). Check Copy the rows too to copy its data as well.

Some engines can't copy everything:

EngineWhat isn't copied
SQLiteIndexes and triggers
MySQL / MariaDBForeign keys
SQL ServerPrimary key, indexes, defaults and constraints

Truncate

Truncate… deletes every row and keeps the table. Mantidb asks: "Delete every row of “<table>” on <connection>? This can't be undone." On SQLite, it runs a DELETE.

Delete

Delete… drops the table and all its rows. Mantidb asks: "Delete table “<table>” and all its rows on <connection>? This can't be undone."

Truncate and Delete always ask for confirmation, even in Silent safe mode. On Production connections they also ask for Touch ID.

On PostgreSQL, Truncate and Delete don't cascade. They fail if another table references this one through a foreign key.

Copy DDL

Copy DDL copies the table's CREATE TABLE statement to the clipboard:

EngineSource
PostgreSQLRebuilt from the system catalog
CockroachDBSHOW CREATE TABLE
Amazon RedshiftSHOW TABLE
MySQL / MariaDBSHOW CREATE TABLE
SQL ServerRebuilt from the sys.* catalog views
SQLiteThe original CREATE statement from sqlite_master

Amazon Redshift tables can be browsed and copied as DDL, but the other table actions aren't available.