Database Constraint Name
In the Entity Relationship Diagram, you can define the constraint name for primary key, unique constraint and check constraint. Using constraint name you can quickly identify and fix any errors and reliably modify or drop constraints.
Setting Constraint Name
Before create any constraint, you need to configure the default database for export database schema.
Select
Tools >
Object-Relational Mapping (ORM) >
Database Configuration… on menu to configure
HSQL as a default database.
Create Table call
person in ER Diagram
| Column | Type | Information |
| id | int | Primary Key |
| lastName | varchar(30) | |
| firstName | varchar(30) | |
| address | varchar(100) | |
| age | int | |
Primary Key
Primary Key is a set of one or more columns in a database table whose values, in combination, are required to be unique within the table.
In person table, you can specify the primary key constraint name for the column id’s primary key.
Select person table and click
open specification on right click popup menu.
Select the
Columns tab and enter the
primary key constraint name call “person_pk”.
Unique Constraint
Unique constraints ensure that every value in the specified key is unique. A table can have any number of unique constraints, with at most one unique constraint defined as a primary key. Following the setting Primary Key Constraint name step, you can create the unique constraint with name.
Select Constraints tab on Entity Specification dialog.
Click
Add button and select
Unique Constraint… button on the pulldown menu.
Select
id,
lastName and
firstName column from
All: list to
Selected: list and enter the unique constraint name call
id_name_uc.
Check Constraint
Check constraint based on a user-defined condition that has to evaluate to true for a record to be valid. Adding check constraint has a similar step of add unique constraint.
Select Constraints tab on Entity Specification dialog.
Click
Add button and select
Check Constraint… button on the pulldown menu.
Enter the check constraint name call
age_limit and enter constraint “age > 18”.
Now the Primary Key, Unique and Check Constraint are created on person table.
Generating Constraint
After configured the default database and added different constraint, you can export the table schema to the default database.
Select
Tools >
Object-Relational Mapping (ORM) >
Generate Database … on the menu.
Configure the
output path; select the
Export to ddl and
Generate ddl options. Click
OK button.
From the export ddl file. You can read each constraint and your assigned name in create person table statement.
CREATE TABLE Person (id integer generated BY DEFAULT AS identity (start WITH 1), lastName varchar(30),
firstName varchar(30), address varchar(100), age integer, constraint person_pk PRIMARY KEY (id),
constraint id_name_uc UNIQUE (id, lastName, firstName), constraint age_limit CHECK (age > 18));
The person table is created on the HSQL database, and then you can try to reverse the person table and all constraints in new project.
Reversing Constraint with Name
Create the other project for reversing constraint with name. You need to configure the previous export person table database.
Select
Tools >
Object-Relational Mapping (ORM) >
Reverse Database … on menu.
Select
Java language on Database to Data Model dialog and click Next>.
Enter the information to configure the HSQL database to import the person table.
Select the person table and click Finish button to reverse.
Select person table and select open specification on right click popup menu and check different constraint name is it correct to reverse for person table.
Notice: the check constraint cannot be reverse from the database, so it is missing in the person table but you can use the check constraint name in database.
Downloads
Resources