New Features
Enhanced Features
O/R Mapping
Tips and Tricks
UML Diagrams
VP Suite

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.

  1. Select Tools > Object-Relational Mapping (ORM) > Database Configuration… on menu to configure HSQL as a default database.
    db_config_menu.jpg

    config_db.jpg

  2. Create Table call person in ER Diagram
    person_tb.jpg

    ColumnTypeInformation
    idintPrimary Key
    lastNamevarchar(30)
    firstNamevarchar(30)
    addressvarchar(100)
    ageint

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.

  1. Select person table and click open specification on right click popup menu.
    before_open_sp_person.jpg

  2. Select the Columns tab and enter the primary key constraint name call “person_pk”.
    set_pk_constraint.jpg

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.

  1. Select Constraints tab on Entity Specification dialog.
    select_entity_specification.jpg

  2. Click Add button and select Unique Constraint… button on the pulldown menu.
    click_add_unique_c.jpg

  3. Select id, lastName and firstName column from All: list to Selected: list and enter the unique constraint name call id_name_uc.

    create_unique_c.jpg

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.

  1. Select Constraints tab on Entity Specification dialog.
  2. Click Add button and select Check Constraint… button on the pulldown menu.
    click_check_c.jpg

  3. Enter the check constraint name call age_limit and enter constraint “age > 18”.
    create_check_c.jpg

    after_create_check_c.jpg

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.

  1. Select Tools > Object-Relational Mapping (ORM) > Generate Database … on the menu.
    generate_db.jpg


  2. Configure the output path; select the Export to ddl and Generate ddl options. Click OK button.

    config_export_db.jpg

  3. 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.

  1. Select Tools > Object-Relational Mapping (ORM) > Reverse Database … on menu.
    reverse_db_menu.jpg

  2. Select Java language on Database to Data Model dialog and click Next>.
    wizard_reverse_1.jpg

  3. Enter the information to configure the HSQL database to import the person table.
    wizard_reverse_2.jpg

  4. Select the person table and click Finish button to reverse.
    wizard_reverse_3.jpg

  5. 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.
    reverse_table.jpg

    reverse_pk.jpg

    reverse_unique.jpg

Downloads


Resources

 
 
Last modified: 2006/06/19 14:52
 
 
Home | Recent Topics | Highlights | UML Diagrams | Tips and Tricks | Object-Relational Mapping
visual-paradigm.com Home | Training Center | UML Center | VP Gallery | Discussion Forum | UML Open Directory