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.

  1. Start DbSchema. The Welcome Screen opens.
  2. In Start New, choose Connect to Database.
  3. Click the tile of your database, such as PostgreSQL.
  4. Press Connect, and fill in the host, the database name, the user and the password.
The Welcome Screen with Connect to Database selected and the PostgreSQL tile chosen

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.

The shop schema in DbSchema: the tree of tables on the left and 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_id points to customers.

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.

  1. Double-click the products header.
  2. In the Columns tab, press Add.
  3. Type the name color, choose the type varchar and the length 30.
  4. 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.

  1. Press Editor in the toolbar and choose SQL Editor. You can also press Ctrl+E.
  2. Type a query, such as:
    SELECT status, count(*) AS orders, sum(total) AS revenue
    FROM shop.orders
    GROUP BY status
    ORDER BY revenue DESC;
    
  3. 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.

  1. Choose File → Export As... → HTML5/PDF Documentation, or press Ctrl+D.
  2. Keep HTML5 and Diagram Vector Image ticked.
  3. Under File Path, choose where to save the file.
  4. Press Generate.
The Schema Documentation dialog with HTML5 selected and Diagram Vector Image and Image Mouse-Over Tooltips ticked

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.

  1. Press Save in the toolbar, or choose File → Save Model to File (Ctrl+S).
  2. Choose a folder and a name for the .dbs file.
The DbSchema toolbar, with the Model, Reopen and Save buttons on the left

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