Columns, data types, and keys
Give each column a name, a data type, and an example value. Mark the columns that make up the primary key, and add defaults, descriptions, indexes, and checks where you need them.
Column, Data type, and Example
Edit columns in the side panel's Edit tab, or double-click a table to edit them right on the canvas. Either way, you'll see the same three fields:
- Column – the column name, such as
order_id. -
Data type – a dropdown with the data types of the database your model
is planned for (choose it under Model in the Edit tab when nothing is
selected), followed by the model's enums. The most common types come first, then the
rest in alphabetical order. Start typing to jump to a type. For a size or precision of
your own, such as
VARCHAR(80)orDECIMAL(10,2), type it in the column's details (below). - Example – a typical value, such as
ORD-1001.
Tables you import from a schema file or pasted CREATE TABLE statements keep
their data types as your database writes them, such as VARCHAR(50) or
NUMERIC(10,2), and the export writes them back the same way. Switching the
model to another database changes every column to the closest type there.
Add a column in the empty row at the bottom: Tab moves between its fields, and Enter saves
the whole row as one undo step. To set the name and data type in one go, type
name: TYPE in the Column field, such as order_id: integer. Common
spellings work too, so quantity: int gets your database's integer type. Each
column name can appear only once in a table, and it can't be all digits.
Primary key, Unique, and Required
At the top of the data type list are three checkboxes: Unique,
Required (NOT NULL), and Primary key. Check Primary key on
several columns for a composite key; the table's details in the Edit tab show the key in
order, and the up and down buttons there change it. Key columns are always required. In the SQL
export, the key becomes the PRIMARY KEY, any other unique column gets
UNIQUE, and every required column gets NOT NULL. On the canvas, a
required column gets a ! after its data type, and a unique column's line ends
with the word unique.
Column details
The arrow at the end of a column's row opens its details, in the side panel and on a card you're editing on the canvas:
- Data type – typed freely, with a size or precision if you need one.
-
Default – the value a new row gets when it doesn't give one, written into
the SQL exactly as you type it, such as
0,'new', ornow(). A default must be a single expression, so a semicolon or a comment is refused. - Generated by the database – an identity, serial, or auto-increment column, written in each database's own way.
- Description – a comment that the SQL export writes for the column.
The arrow turns blue when a column has details, so you can spot them at a glance.
Table details
Below the columns, the Edit tab has the selected table's schema (such as
sales or dbo; leave it empty for the default) and
description, its primary key in order,
indexes (an optional name, the columns in order, and Unique), and
check constraints (an optional name and a condition such as
quantity > 0). Two tables can share a name in different schemas.
Reorder columns
Drag a row by the dots at its far left, either in the side panel or on the canvas. A line shows where the row will land. The export writes the columns in the same order, and the first column's example value appears on the card as its caption.
Paste several columns at once
Paste one of these into the Column field of the empty row at the bottom, and we'll add all of its columns in a single undo step:
-
A
CREATE TABLEstatement. Each column gets a matching data type.NOT NULLmakes a column Required,UNIQUEmakes it Unique, and a single-column primary key makes it both. -
A table copied from a spreadsheet or database tool, with or without a
header row, and with tabs, commas, or
|between cells. The output ofDESCRIBEworks too. - JSON, or a list of objects. Each value becomes the column's example, and we work out the data type from it: INTEGER, FLOAT, BOOLEAN, DATE, LOCAL DATETIME, or ZONED DATETIME; a LIST type when every item in a list has the same type; and STRING for any other text.
- Lines such as
name: TYPE (example)orname: value.
If a column already exists, we keep its data type, example, and settings and only fill in what's missing. A message sums up what was added and what already existed.
How columns are drawn
On a card, the columns fill the space below the caption in three columns: column name, data type, and example value. A small PK marks the primary key's columns and FK the columns a foreign key holds. With Square mode off, a table's columns are listed in a box below its circle, one per line, as name: TYPE (example) or whichever parts you've filled in. To style the cards, open the Format tab. To show or hide every column at once, use the Columns layer in the Layers tab. SQL and JSON exports always include every column, even when that layer is hidden.
For teams that also use Neo4j
The Cypher export translates each data type to the closest Neo4j property type, turns the primary key into constraints, and writes each example value to match its type. See Export.