 | Starting top down from logical models
Logical modeling deals with gathering business requirements and
converting those requirements into a model. The logical model revolves
around the needs of the business, not the database, although the needs
of the business are used to establish the needs of the database.
Modeling architects deal with logical modeling. When the model design
meets the necessary requirements, they get translated to physical
models and finally get deployed as physical artifacts to the database.
This is a more typical scenario for new applications. Here is how you
do it.
- Right-click on the storesModel project, and select
New > Logical Data Model. Give the model
the name, storesLogicalModel and then click on
Finish. A new Editor will come up on the right of the
screen, as Figure 21 shows:
Figure 21.
Creating a new logical model
Note: Because this is at the logical model level, we will deal
with logical level items rather than database level items. So,
in this model, we add entities, attributes and relationships
and the like. When this model gets transformed to a physical
model, the entities get mapped to tables, attributes get
mapped to columns, and so on.
- Let's create the model of a simple Book Store, as shown in
Figure
22. The
entities in this model are Book, Author, and BookCategory. For
each of the Book entities, there could be more than one Author,
and each Book gets slotted into one or more BookCategory entities.
So there is a one-to-many relationship between Book and Author
entities and BookCategory entities.
Figure 22.
Model that we will be creating
- Create the entities and attributes using the Palette designer to
the right of the diagram window, as shown in Figure 23:
Figure 23.
Creating an entity
You can add elements to the entity by right-clicking (or
hovering) on the entity and using the two buttons that appear
(as shown in Figure 24) to add a Primary
Key or attributes. Alternatively, you can add attributes in
the Property Dialog on the bottom.
Figure 24.
Adding attributes
Follow these steps to create all three entities and their
primary keys and relationships:
- Create the Book entity.
- Add primary Key BookID.
- Add Attributes ISBN, DatePublished, BookTitle, and
BookComments.
- Set the types, as shown in Figure 25:
Figure 25. Properties of the Book
entity
- Create the BookCategory entity.
- Add primary key BookID.
- Add attributes CatCode and CatDes.
- Set the types, as shown in Figure 26:
Figure 26. Properties of the BookCategory
entity
- Create the Author entity.
- Add primary keys BookID and AuthorID.
- Add attributes AuthorName and AuthorBio.
- Set the types, as shown in Figure 27:
Figure 27. Properties of the Author
entity
- Add relationships by using the Palette designer. Alternatively,
hover over the parent entity and drag the arrow to the desired
child entity, as shown in Figure 28:
Figure 28.
Adding relationships
- Create a relationship between Book and BookCategory. Drag
the arrow Book to BookCategory, select Create
Identifying Foreign Key Relationship, and pick
Use the Existing Child Attribute/Column in the
dialog that shows up.
- Use the exact same method to create a relationship between
Book and Author.
- Once the logical model has been created, save the model by
clicking on the Save button in the main toolbar. You can
use the property view to change the type or any other detail for
the entities.
- Once you are done with your logical model, let's transform it to a
physical model. Here are the steps to accomplish this:
- In the storesModel project, navigate your way to
storesLogicalModel.ldm.
- In the main toolbar on top, click on the Transform to
Physical Data Model button. Refer to
Figure 18 to see where the button is. It
is located next to the Transform to logical model button.
- Select Create New Model and click on Next.
- Choose Informix from the database drop down and click
on
Next.
- Leave defaults on in the next screen and click on
Next.
- Click on Finish.
This creates a folder called storesLogicalModel.dbm in the Data Models
folder and also in the Data Diagrams folder. Look at the diagram, and
you will see Tables and Columns in the physical model, as Figure 29
shows:
Figure 29. Physical
model for the BookStore
Things you can do now
Now that you have a physical model, you can enhance the model further
by adding any database-related entities (like indexes and triggers).
For example, to add a trigger to the table Book, right-click on
Book > Add Data Object >
Trigger (Figure 30) and define the logic that goes into
your trigger. Remember to save it:
Figure 30. Add a
trigger to the Book table
Also, you can generate DDL statements and deploy them to the database.
Do this by right-clicking on an object (such as a table) and then
clicking on Generate DDL. Figure 28 shows you
how to get to the Generate DDL option. Using the wizard, you can
either save the script or run it on the server. You can create a
single script for your entire physical model as well.
|  |