Specifying default data in database design

Database Visual ARCHITECT (DB-VA) allows you to design your database with entity relationship diagram (ERD), and finally generate the design to database as database schema. On top of the schema that will be generated, you can also specify default data to insert into database upon database generation. In this tutorial, we will draw a simple ERD with three entities, specify default data and generate database.
You are expected to have a fundamental knowledge on database modeling with ERD and database engineering.

August 16, 2010
User Rating: / 2
Views: 2,007
PDF Link Add comments

Setting up your database

MySQL will be used as database software throughout this tutorial. You can, however, use any other types of database products that we support. When you are familiar with the database software you are using, it won't be hard for you to complete this tutorial.

Create a database and name it as myshop in advance.


create db

Creating new project

Create a new project with starting DB-VA. Select File > New Project from the main menu. In the New Project dialog box, name the project as My Shop Model and click Create Blank Project button.


new project

Configuring your database

  1. Select Tools > Object-Relational Mapping (ORM) > Database Configuration... from the main menu.
  2. In the Database Configuration dialog box, check MySQL to select it as the target database.
    select db
  3. In the Database Setting panel, press the green down arrow button next to Driver file field to let DB-VA download the driver for you.
    download driver
    If your database provider does not support downloading driver file, the pop-up Download dialog box will notify you that the database software is not available and provide a link for downloading the driver file.
    warning dialog
    Alternatively, you can refer to Database Driver Description section for information on downloading the driver file.
    db driver desc
  4. Fill in the connection information for connect to database. Enter myshop as database name. Select InnoDB as engine to keep the relationships among entities when generating database. Click on Test Connection to verify the connection. Click OK to close the configuration dialog box.
    connect info

Drawing an ERD

  1. Create an ERD. Right click on Entity Relationship Diagram in Diagram Navigator and select New Entity Relationship Diagram from the pop-up menu.
  2. Name the diagram as MyShop ERD using the rename box at the top left corner. Keep Physical Model selected at the top right corner.
    diagram name
  3. Next, create an entity. Press on Entity on diagram toolbar and drag to the diagram. Name it as PurchaseOrder and press Enter to confirm.
    create purchase order
  4. A purchase order consists of many products, while a product can appear in many purchase order. This is a typical example of many-to-many relationship. Now, create the product entity. Move the mouse pointer to the entity PurchaseOrder, press on the resource icon Many-to-Many Relationship -> Entity, drag it out and then release the mouse button to confirm. Name the entity as Product.
    create product
  5. Add columns to the entities. Right click on PurchaseOrder and select New Column from the pop-up menu. Enter +id:int as name (note: The plus sign indicates that this is a Primary Key column). Press Enter.
    new col
  6. Follow the table below to add columns in all entities.
    Entity Column
    PurchaseOrder +id : int (10),
    staff : varchar(255)
    Product qty : int(11)
    PurchaseOrder_Product +id : int(10),
    name : varchar(255)

    The result of diagram is shown as below:
    completed erd

Entering default data

  1. Select PurchaseOrder. You can see the table record editor appears at the bottom of diagram lists the columns for you to add default data. If you do not see the editor, right click on the ERD's background and select Show Table Record Editor from the pop-up menu.
    record editor
  2. Double click on the id cell and enter 1. Then, double click on the staff cell and enter Mary. Press Enter.
    created purchase order
  3. Follow the table below to add records in PurchaseOrder entity.
    Id (PK) staff
    1 Mary
    2 David
    3 Paul
  4. Repeat the previous steps to add records in Product entity. Here are the records to add:
    Id (PK) name
    1 Shapmoo (500 ml)
    2 Battery (AAA)
  5. Select PurchaseOrder_Product entity.
  6. In the editor, select 1 in PurchaseOrderid and 2 in Productid, and then enter 5 in qty.
    select po id
  7. Add records to the PurchaseOrder_Product entity. Here are the records to add:
    PurchaseOrderid (PK+FK) Productid (PK+FK) qty
    1 2 5
    2 1 2
    3 1 1
    3 2 1

Generating database

  1. Select Tools > Object-Relational Mapping (ORM) > Generate Database... from the main menu.
  2. In the Database Code Generation dialog box, check Export to database and Generate sample data. If you do not select them, both database and sample data will not be created in database.
    check option in db gen
  3. Click OK button to start generation.

Checking your database

You can now check your database to see if the schema and default data are both generated. Here is a screenshot captured under MySQL, for checking the generated schema.


check schema
This is another screen that shows the default records added to database.
check data

Rate this Article

Click on one of the stars below to rate this article from 1 (lowest) to 5 (highest).

You may be interested in

  1. Oracle database design with Entity Relationship Diagram
  2. Oracle Database Design Tool
  3. Oracle database reverse engineering
    Tagged:
  4. Relational Database Design with ERD
  5. Generate Hibernate map with Oracle database
Tags of this article:

Comments (0)

Write comment

Rating

Comment

Enter the calculation result

security code