Database Schema

Databases store data based on the schema definition, so understanding it is a key part of designing databases. In this chapter, we will cover some of the key aspects related to the schema definition.


In the Relational Databases, the schema is composed of a grouping of tables. We can think of the schema as a blueprint of the database. A schema can contain only one table with a certain name.


A database table is a collection of data focused on a specific topic. A database can have more tables related through foreign keys. Each table is made up of columns and rows. You can create a table in DbSchema by right-clicking on the empty layout and selecting "Create New Table". Find out more about how to create tables here.
Table in Layout

Editing tables

You can edit tables in DbSchema by double-clicking on the table header.

Table Editor


As we mentioned before, every table is made up of columns and rows. Each column can contain only one type of data (numeric, letters, etc.). For some columns, precision and/or decimal is required. The precision refers to the maximum number of characters allowed in the cells of the columns, while the decimal refers to the maximum number of decimal digits.

Learn more about how to create or edit columns here.

As shown in the first image, each column has a symbol that represents proprieties or foreign keys relations. To edit a column just double-click it in the layout diagram.

Each column may have other properties:


As an index of contents in a book, indexes provide a quick way to find the exact data item you want. Indexes must have one or more columns.
Indexes can be:

Index Editor

Foreign Keys

A foreign key is a column or group of columns in a table that acts as a constraint. The foreign key enforces that data from one column (referencing) must exist in another column (referenced). Each value of the foreign key column should have a corresponding value in the linked table. The referenced column can only be a primary key or unique column.

The foreign key columns are marked with a small arrow on the right side of the column. Click it to add the table on the other end of the foreign key to the layout.

Double-clicking any of the foreign key lines in the layout will open the Foreign Key editor. One foreign key must have at least one pair of columns.

If the referencing column is NULL, the check will not validate this value. NULLs are allowed in this column only if the column is not mandatory.

One-to-one, one-to-many, and many to many foreign keys

The relation cardinality is a consequence of how the column and the indexes are created. Having different combinations of NOT NULL and UNIQUE indexes will lead to one of the referencing types below.

Referencing columns (from)Foreign Key TypeRepresentation (See Layout Menu - Fk Notation)
Not nullUnique
nono1:n (one to many)dashed line, 3-lines foot
noyes1:0 or 1 (one to zero or one)dashed line
yesno1:many (one to many)3-lines foot
yesyes1:1 (one to one)

Here in DbSchema under the default notation:

FK Notation
Or in Barker Notation ( you can set the notation from the Layout Menu ) :
FK Notation Barker

For the case one or more records from the primary key ( referred ) column are deleted or updated, you can set for each foreign key:

If the database lacks a certain foreign key, you can create virtual foreign keys, that will be implemented only in DbSchema. This won’t affect the database in any way. The foreign key is saved in the model file. It can be used in Queries or Data Editor to simulate a real foreign key.

Composite foreign keys include two or more columns on each side. In this case, in the Foreign Key Editor, there will be more columns listed. Each of the column values will match in the referred table. The primary key or unique index in the referred table will be defined as well on multiple columns.


Constraints are validations of the data on insert or update. Two types of constraints can be defined :

Always use meaning-full names for constraints. For the constraint age > 18 use the name 'CheckAgeOver18'. If a user may try to insert the value 14 in the field age, he will get back in DbSchema or software 'Error: Constraint CheckAgeOver18 failed' which is easy to understand. If you name the constraint like 'Check214' you can imagine what he can understand from 'Error: Constraint Check124 failed'.

Constraints are useful to enforce data integrity, eq. have no incorrect data. Mistakes can occur via human errors when data is entered, computer or software errors, etc. Setting constraints may save a lot of trouble in the software.

Foreign Keys are also constraints. They are enforced via internal database triggers, so each time a new record is inserted or verified, the inserted record is verified against the trigger condition.


Views are SELECT queries that simulate a table. The view columns are the columns listed in the SELECT clause.

Views can be a clean way for the programmers to move their queries inside the database. Instead of keeping complex SELECTS in the application logic, you can create views. The view creation statement is saved in the database.

In the View Editor, you can edit and test the query view statement. The view columns are automatically added to the diagram after testing the view query against the database.

You can create virtual foreign keys between views and views or views and tables. They are useful in Data Editor or Query Builder to explore data from multiple tables or create join queries between views.

View Editor


A sequence is an auto-increment number generator, like auto-increment. Sequences are used to generate the values for the Primary Key columns.

MySql does not have sequences, so it uses IDENTITY columns instead. These columns are automatically filled by the database and don't require any value.

Sample: in the table PERSONS( ID integer identity, FIRSTNAME varchar(100)) you can do 'INSERT INTO PERSONS( FIRSTNAME ) VALUES ( 'Lulu')'. The database will fill in the ID column.

For Oracle, you have to create a sequence. DbSchema will execute 'CREATE SEQUENCE MYSEQ' in the database. You will use: 'INSERT INTO PERSONS( ID, FIRSTNAME ) VALUES ( MYSEQ.nextval, 'Lulu')'

Procedures, Functions & Triggers

Procedures, Functions, and Triggers are Procedural Language ( PLSQL ) pieces of code. They are edited and created in DbSchema using the SQL Editor. You can double-click one of the Procedures, Functions, or Triggers in the Tree Pane to open them in the SQL Editor.
View Editor 2

Procedures can execute some operations in the database without returning any value. Functions will compute something and return a value. Triggers are fired by INSERT, UPDATE, or DELETE operations in the database.
Usually, you can do COMMIT or ROLLBACK only in procedures. Functions or triggers can't execute commit or rollback. The operation calling them to has to commit or rollback.

The procedures, triggers, and functions are written in a database-specific language. If you decide to convert the schema from one database to another, you have to re-write them.