Help home > ER Diagrams and Table Specifications
ER Diagrams and Table Specifications
Create ER diagrams from the foreign keys in your database and export them as images or PDF. You can also produce table specifications (Excel or HTML).
What you can do
| Task | How to open |
|---|---|
| Create an ER diagram of every table in a schema | Right-click a schema in the tree and choose "Create ER Diagram (All Tables)" |
| Create an empty ER diagram | 🔗 New ER diagram in the top bar |
| Open a saved ER diagram | "File" → "Open ER Diagram..." in the menu |
| Table specification | Right-click a schema or table in the tree and choose "Export Table Definition Document (Excel / HTML)...", or use Export ▾ in the ER diagram |
| Text for AI | Right-click a schema or table in the tree and choose "Copy Table Structure for AI...", or use Export ▾ in the ER diagram |
Getting started: creating an ER diagram (3 steps)
Open an ER diagram
Right-click a schema in the tree and choose "Create ER Diagram (All Tables)". Tables are arranged automatically, with parent tables above child tables.Tidy up the layout
Drag tables to move them. Auto Layout rearranges them, and Fit to Window zooms so the whole diagram is visible.Export
Choose SVG, PDF or clipboard from Export ▾.
Adding tables
- Drag: Drag a table from the tree onto the ER diagram to add it where you drop it. Drag the "Tables" folder to add every table and arrange them automatically.
- Right-click: Right-click a table in the tree and choose "Add to ER Diagram".
- Pick from a list: + Add Table.
- Related tables: Right-click a table in the ER diagram and choose "Add Related Tables" to add the tables it references.
Reading the lines (IE notation)
Choose the line shape with Lines: Straight / Lines: Right-angled in the toolbar. "Right-angled" routes lines horizontally and vertically, going around any entities in the way. Musubi SQL also picks the sides and positions where lines enter and leave so that lines cross each other and end symbols overlap as little as possible (the chosen shape is saved with the ER diagram). Where two lines cross, one of them hops over the other with a semicircle, so you can tell a crossing from a connection (with right-angled lines, the horizontal line hops).
How cardinality is determined: By default, cardinality is derived from the foreign key columns as follows. In a table, PK marks primary key columns and FK marks foreign key columns.
| End | Automatic cardinality |
|---|---|
| Parent (referenced side) | "Exactly One" if the foreign key columns are NOT NULL; "Zero or One" if they allow NULL |
| Child (side with the foreign key) | "Zero or One" (one-to-one) if the foreign key columns are a primary key or unique index; otherwise "Zero or More" |
- Changing it by hand: Right-click a line and choose "Child Side: Zero or More / One or More / Zero or One / Exactly One" or "Parent Side: Exactly One / Zero or One". This lets you show business rules that database constraints can't express, such as "every parent has at least one child".
- Cardinality you set by hand is saved in the ER diagram file (the database doesn't change). "Reset Cardinality to Automatic (from Foreign Key Columns)" switches back to automatic.
- Many-to-many (N : N): Add a junction table (for example, OrderItem linking Order and Product) and draw one-to-many relationships from both sides.
Operations
| Action | Result |
|---|---|
| Drag a table | Moves it (snaps to a 10-unit grid) |
| Ctrl+drag | Selects the tables, text and callouts in the rectangle (anything touching the rectangle is added to the current selection). Ctrl+click selects or deselects one item at a time |
| Drag a multiple selection | Moves them together, keeping their arrangement. Delete removes them all; Esc or clicking the background clears the selection |
| Drag the background, mouse wheel | Pans the diagram |
| Ctrl+wheel, - + | Zooms in and out |
| Double-click a table | Opens the table definition (for a new entity, the designer) |
| Delete, or right-click → "Remove from ER Diagram" | Removes it from the ER diagram (the database table is not deleted) |
| Ctrl+Z, ↶ | Undo (adding, removing and moving tables, auto layout, applying designs). Ctrl+Y or ↷ redoes |
| Hover over a line | Highlights the line in blue and the tables at both ends in orange, so you can tell overlapping lines apart |
| Hover over or click a table | Highlights the table in blue and the connected tables and lines in orange (when you move the mouse away, the relationships of the selected table are shown) |
| Display names, Types, Keys only | Switches between logical names, physical names and both (Ctrl+L), shows data types, and shows only primary key and foreign key columns. These are per-diagram settings, separate from the app-wide display names |
| Hide common columns | Hides the common columns (created at, updated by and so on) defined in the connection settings. Foreign key lines made only of common columns (such as CreatedBy → User) aren't drawn either. Primary key columns stay visible. Saved per diagram. When common columns are shown, their names are drawn in a greenish color to set them apart |
| Auto Layout | Rearranges tables with parents (referenced side) above and children below. Children are placed directly under their parent and parents are centered over their children, so lines run vertically and horizontally as much as possible |
| Reload from DB | Reloads the table definitions |
New entities and DDL
+ New Entity adds a table that doesn't exist in the database yet (with a yellow header). Double-click it to open the designer (see Creating a table in the GUI), and click Apply to ER Diagram to bring it back into the diagram. Generate DDL creates the DDL for the new entities in a SQL tab, or for every table in the diagram if there are no new entities.
Creating and deleting relationships
- Click Create Relationship (or right-click an entity and choose "Create Relationship (Drag from Here to the Parent Table)").
- Drag from the child table (the side with the foreign key) to the parent table (the referenced side). Esc cancels.
- In the dialog, map the child table's columns to the parent table's columns. Columns matching the parent's primary key are selected automatically, and you can add columns the child lacks with "+ Create a new column".
- New entities: The foreign key (and any new columns) are added to the design. Apply them to the database with "Generate DDL".
- Database tables: Run the ALTER statement that adds the foreign key with Run and Create, or review it first with Open in SQL Tab.
- Deleting: Right-click a line and choose "Delete Relationship". For database tables, this runs an ALTER statement that drops the foreign key.
SQLite can't add or drop foreign keys with ALTER (the table has to be recreated).
Virtual relationships (relationships without a foreign key constraint)
Define a relationship in the ER diagram only, without creating a foreign key constraint in the database. Use this to record relationships between tables where you don't want a constraint.
- Creating: Click Add as Virtual Relationship in the Create Relationship dialog. The database isn't changed, so you can do this without a connection. For database tables, only existing columns can be used (no new columns). For new entities, "+ Create a new column" adds columns to the design. The columns are included in the DDL, but the foreign key constraint is not.
- Display: The line is dashed. Hover over it to see " (virtual)" after its name.
- Saving: Saved in the ER diagram file (.msqer). Share the file and others can use the same relationships.
- Using them elsewhere: Virtual relationships in an ER diagram linked to a connection are also used, for the same connection, by automatic joins in the SQL Builder, test data generation (picking from parent table values) and table specifications (listed under foreign keys and Referenced by, marked " (virtual)"). They take effect when you save the ER diagram.
- Deleting or creating in the database: Right-click the dashed line and choose "Delete Virtual Relationship", or "Create Foreign Key Constraint in Database (Run ALTER)..." to turn it into a real foreign key (for new entities, "Add to Design as Foreign Key Constraint (Included in DDL)" includes it in the DDL). If the database already has a foreign key on the same columns, the virtual relationship isn't drawn.
- Removing a table from the ER diagram also removes its virtual relationships (Ctrl+Z brings them back).
Text and callouts
Use + Text / Callout ▾ to add notes to the diagram. Line breaks are allowed (Ctrl+Enter confirms).
- Text: For diagram titles and notes. Callout: For pointing at a table or other item and explaining it. When selected, a blue dot appears at the tip; drag it to change where the callout points.
- Drag to move, double-click to edit the text, and press Delete to delete.
- Right-click to change the font size (Small, Normal, Large, Extra Large), bold, color, and whether the callout has a pointer.
- Text and callouts are saved with the ER diagram and included in SVG, PDF and clipboard exports.
Page borders and per-page PDF
Page: A4 Landscape ▾ shows border lines that divide the diagram into print areas by paper size (page borders). The number at the top left of each border is the page number.
- Paper can be A4, A3, B4, B5 or Letter, in portrait or landscape. Whether borders are shown and the paper are saved per diagram.
- The borders appear only on screen and are not exported. Place tables so they don't straddle a border for clean printouts.
- Export ▾ → "Page by Page → Save as PDF File..." exports each page border as one PDF page. Empty pages are skipped.
Export (SVG, PDF, clipboard)
From Export ▾, choose the area and the destination.
| SVG file | Clipboard | PDF file | |
|---|---|---|---|
| Whole Diagram | ○ | ○ | ○ |
| Select Area | ○ | ○ | ○ |
- Select Area: Drag a rectangle around the area to export. Esc cancels.
- Clipboard: Copies both an image (PNG at 2× resolution) and SVG. You can paste it as an image into Excel, PowerPoint, Paint and so on. If you need the SVG source, use "Save as SVG File".
- PDF: Exports a single page the size of the diagram. To split it by paper size, use per-page PDF.
- Transparent background: Check Export ▾ → "Transparent Background (SVG and Clipboard)" to make the background of SVG files and clipboard images transparent (table interiors stay white). PDF always has a white background.
Exports always have a white background regardless of the app theme (unless the background is transparent).
Saving and opening
ER diagrams are saved as .msqer files. Table definitions are saved with the diagram, so you can open it offline. Display names, Types, Keys only, Hide common columns, line shape, zoom and scroll position are also saved and restored the next time you open it (changing only the zoom or scroll position doesn't mark the diagram as unsaved).
- Saving: Save (Ctrl+S) overwrites the file. For a diagram that hasn't been saved yet, you choose where to save it. ▾ → "Save As..." (Ctrl+Shift+S) saves to another file. When you save to a new file, the diagram takes the file name.
- Linking to a connection: ▾ → "Link to Connection (Show in Tree)". The diagram appears in the 📐 ER Diagrams folder under the connection in the tree, and you can open it with a double-click. The connection settings store only the location of the ER diagram file (a link); the diagram's contents stay in the file. So the diagram must be saved to a file before linking (a new or modified diagram is saved first, then linked).
- Unlinking: Right-click the ER diagram in the tree and choose "Unlink (Keep the File)", choose ▾ → "Unlink from Connection (Keep File)" in the ER diagram, or click Unlink under "Linked ER diagrams" in the connection settings dialog. The file isn't deleted.
- If a linked file is moved or deleted, the link is ignored (it isn't shown in the tree). The connection settings dialog shows "(file not found)" for it, so you can unlink it there.
Table specifications
Choose the tables, title, format (Excel or HTML) and items (indexes, foreign keys, Referenced by) to export.
| Contents | Excel | HTML |
|---|---|---|
| Table list (logical name, physical name, schema, type, description) | First sheet (with links to each sheet) | At the top (with links to each table) |
| Definition of each table (columns, indexes, foreign keys, Referenced by) | One sheet per table | One section per table (each table starts on a new page when printed) |
The column table lists No, logical name, physical name, data type, NOT NULL, default, PK, description and remarks (auto increment, references). "Referenced by" lists foreign keys in other tables that reference this table (searched among the exported tables).
Text for AI
Choose "Text for AI" as the format to export text that tells an AI such as ChatGPT or Claude about your database structure, to the clipboard or a file (.sql). Paste it before your question, and the AI is more likely to write SQL with the right table names, column names and join conditions.
- The format is close to the CREATE TABLE of the target database. Logical names and descriptions of columns and tables go in
--comments at the end of each line. - Indexes, Foreign keys: When foreign keys are not included, the reference is written in the column comment as "→ table.column". Virtual relationships are written as comments marked "virtual".
- View definition SQL: Writes the columns and the definition SQL of the selected views.
- Omit common columns: Appears when common columns (created at, updated by and so on) are defined in the connection settings. Common columns are written once at the top, and each table just says "has common columns" (this cuts the length when there are many tables).
- After the export, the number of tables and characters is shown. AIs limit how much text they accept at once, so narrow down the tables if it's too much.
FAQ
A table shows "(Could not get the definition)"
The table doesn't exist in the ER diagram's connection. Check the connection in the list at the top left. Hover over the table to see the cause.
Lines don't appear
Lines aren't drawn when the table a foreign key references isn't in the ER diagram. Right-click and choose "Add Related Tables" to add it.
▲ Back to top