New Features
Enhanced Features

Specifying decimal places of the DB type

The data type specifies what type of data the column can hold. You also can specify a maximum for some columns. For example varchar(length) , it holds a fixed length string and the fixed size can specified in parenthesis. For decimal (precision, scale), it hold number with fractions. The maximum numbers of digits are specified in “precision”. The maximum number of digits to the right of the decimal is specified in “scale”. The DB Visual Architect (DB-VA) support configure the “length”, “precision”, “scale” for different kind of data type in Entity Relationship Diagram’s (ER Diagram) column.

Reverse Database to ERD

The following part, you will create the table call “accounts” in MySQL database. The accounts table contains different type of column with “length”, “precision” and “scale”. It will demonstrate how the DB-VA to reverse the column and specify precision to ER Diagram.

  1. Create table “accounts” with the following column in MySQL Database.
    Column nameData typeConstraint
    account_nointPrimary Key
    cust_noint
    account_typevarchar(3)
    int_ratedecimal(4,2)
    free_transint
    ovd_limitdecimal(9,2)

  2. Type the following SQL statement to create accounts table in MySQL database.
    CREATE DATABASE test;
    USE test;
    CREATE TABLE accounts (account_no int, cust_no int NOT NULL, account_type varchar(3) NOT NULL,
    int_rate decimal(4, 2) NOT NULL, free_trans int(3) NOT NULL, ovd_limit decimal(9, 2) NOT NULL,
    PRIMARY KEY(account_no));
  3. Open new Project “Test Precision” in DB-VA.
    create_project.jpg

  4. Select ToolsObject-Relational Mapping (ORM)Reverse Database … on menu bar.
    menu_reverse_db.jpg

  5. Select Java Language and click Next.
    reverse_lang.jpg

  6. Select MySQL (Connector/J Driver) driver and enter the information and then click Next.(must be set as default because the MySQL setting will use again for export update schema)
    reverse_config_db.jpg

  7. Select the accounts table to reverse and click Finish.
    reverse_sel_table.jpg

  8. The ER Diagram is generated include the accounts table.
    erd_accounts.jpg
    From accounts table, you can see that contain the entire column and include the length, precision and scale of different data type.

Specifying decimal places of the DB type

Now the accounts table is generated on ER Diagram, you can create the relative table call account_stmt. The account_stmt table contains column call acct_balance with data type decimal. You need specify the precision 9 and scale 2 in acct_balance column specification. decimal(9, 2) is a number that has 9 digits before the decimal and 2 digit after the decimal.

  1. Create account_stmt table on ER Diagram.
    Column nameData typeInformation
    stmnt_nointPrimary Key
    stmnt_date_todate
    stmnt_date_fromdate
    acct_balancedecimal(9,2)

  2. Create the columns in account_stmt table.
    account_stmt_table.jpg

  3. Edit the acct_balance column decimal data type’s precision and scale.
    • Enter precision and scale values on acct_balance column directly.
      precision_scale_direct_erd.jpg

    • Fill in the precision and scale values in Column Specification dialog.
      open_column_specification.jpg

      precision_scale_specification_dialog.jpg

  4. Create the one to many relationsip from accounts to acct_smt table.
    sel_1_to_m_accounts.jpg

    created_relationship.jpg
  5. Rename the foreign key column from Accountsaccount_no to account_no.
    change_fk_name.jpg

  6. Select ToolsObject-Relational Mapping (ORM)Generate Database…on menu bar.
    menu_gen_db_dialog.jpg
  7. Select Update Database for Generate Database and Export to database and Click OK to export ER Diagram to database.
    db_code_gen_dialog.jpg

  8. Use show create database statement to view the structure of the account_stmt table in MySQL database.
    DESC account_stmt;

    desc_account_stmt.jpg
    The acct_balance column’s precision and scale success export to the database.

Downloads

Related Articles

Resources

 
 
Last modified: 2006/04/01 11:47
 
 
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