DbSchema Tutorial
This tutorial takes you once through the main features of DbSchema, in six short steps. Each step links to the page that covers it in full.
The pictures use a small shop database in PostgreSQL: customers, orders, products and the tables around them. You can follow along with your own database, or with a sample project, which needs no database at all.
Connect to a database
DbSchema reads the tables of your database and draws them as diagrams.
- Start DbSchema. The Welcome Screen opens.
- In Start New, choose Connect to Database.
- Click the tile of your database, such as PostgreSQL.
- Press Connect, and fill in the host, the database name, the user and the password.
DbSchema downloads the JDBC driver, the piece of software that talks to your database, the first time. Then it asks which schemas to read. See Connect to a database for every field of the connection dialog.
No database at hand? Press Sample Projects at the bottom of the Welcome Screen instead.
Read the diagram
DbSchema shows the tables in the tree on the left and on the diagram in the middle.
- Each box is a table, with its columns.
- A key icon marks the primary key, the column that identifies each row.
- A line between two tables is a foreign key: a column that points to a row in another table. For example,
orders.customer_idpoints tocustomers.
Drag a table header to move the table. See Diagrams for layouts, colors and several diagrams per model.
Add a column to a table
Double-click a table header to open the table dialog. There you change the table without writing SQL.
- Double-click the products header.
- In the Columns tab, press Add.
- Type the name
color, choose the typevarcharand the length30. - Press OK in the column dialog, then OK in the table dialog.
You are connected, so DbSchema runs the ALTER TABLE statement in the database at once.
The History pane at the bottom left keeps the SQL that ran.
See Tables, columns and indexes for every option of the table dialog.
Run a query
The SQL editor runs SQL against the connected database.
- Press Editor in the toolbar and choose SQL Editor. You can also press Ctrl+E.
- Type a query, such as:
SELECT status, count(*) AS orders, sum(total) AS revenue FROM shop.orders GROUP BY status ORDER BY revenue DESC; - Press Run.
The result shows in the grid under the query. The editor completes table and column names as you type. See SQL Editor.
To query with the mouse instead, choose Query → Query Editor. See Query Builder.
Generate documentation
The HTML5 documentation is one file with the diagram and a description of every table. It needs DbSchema Pro.
- Choose File → Export As... → HTML5/PDF Documentation, or press Ctrl+D.
- Keep HTML5 and Diagram Vector Image ticked.
- Under File Path, choose where to save the file.
- Press Generate.
With Preview in Browser ticked, the document opens in your browser. The table and column comments show as tooltips when you move the mouse over the diagram. See Schema documentation.
Save the model
The model keeps your diagrams, and it opens again without a database connection. Saving it to a file needs DbSchema Pro.
- Press Save in the toolbar, or choose File → Save Model to File (Ctrl+S).
- Choose a folder and a name for the
.dbsfile.
Next time, open the model from the Reopen tab of the Welcome Screen.
To share it with your team, put the .dbs file in Git. See Git.
Next steps
- Compare the model with the database: deploy a design, or bring the database's changes into the model.
- Data Explorer: browse rows and follow foreign keys from table to table.
- Data Generator: fill a test database with realistic random data.
- Menus and Layout: where every command sits.
- Licensing: editions, the free trial and license types.