GUI Tools Working with Table

Constraint

You set constraints on the columns of a table in its Structure tab. To open it, click Structure at the bottom of the window or press ⌃ + ⌘ + ]. Changes are kept locally until you press ⌘ + S1 to commit them to the server.

NOT NULL constraint

  1. Open the table's Structure tab.
  2. Set the column's is_nullable field:
    • NO adds the NOT NULL constraint, so the column can't contain NULL.
    • YES removes the NOT NULL constraint.
  3. Press ⌘ + S to commit the change.
is_nullable menu with YES and NO in the Structure tab

PRIMARY KEY constraint

The primary key of the table is shown in the Primary field at the top of the Structure tab.

  1. Open the table's Structure tab.
  2. Edit the Primary field:
    • Add a column name to include that column in the primary key. TablePlus suggests the table's columns as you type.
    • Delete a column name to remove that column from the primary key.
  3. Press ⌘ + S to commit the change.
Primary field at the top of the Structure tab

FOREIGN KEY constraint

  1. Open the table's Structure tab.
  2. Click the arrow in the column's foreign_key field and choose Create a foreign key on column name.
  3. In the popover, choose the Referenced Table and the Referenced Columns, and the On Update and On Delete actions (NO ACTION, RESTRICT, CASCADE, SET NULL, or SET DEFAULT). Click OK.
  4. Press ⌘ + S to commit the change.
Foreign key menu on the customer_id column of the orders table

The same menu lists the existing foreign keys of the column, for example → customers(id). Choose one to see its details, change it, or click Delete to remove it.

Foreign key popover for orders.customer_id referencing customers.id
Foreign key details

TablePlus can't add or remove foreign keys on an existing SQLite table. You can still view them.

DEFAULT constraint

  1. Open the table's Structure tab.
  2. Enter the default value in the column's column_default field, or click the field's arrow to choose one: EMPTY, NULL, or a common default for your database, such as CURRENT_TIMESTAMP or NOW(). Choose Advanced... to set an expression, or a sequence on PostgreSQL.
  3. Press ⌘ + S to commit the change.
column_default menu in the Structure tab

  1. On Windows and Linux, use Ctrl + S. ↩︎