Using ERwin Data Modeler
Using ERwin Data Modeler
Database Design
ERwin is a database design tool used to create Entity Relationship (ER) diagrams. You can
use the Graphical User Interface (GUI) of ERwin to create and maintain graphical models
that represent databases and their structures. The models can be implemented across
different platforms, such as Oracle, SQL Server, and Sybase.
This ReferencePoint explains how to create a data model using ERwin. It also describes the
different features of Erwin, such as layering and transformation.
Each data model has two components - logical and physical. The logical component
establishes the data requirements to implement business rules. It also represents business
rules using entities, attributes, and the relationships between them. The physical component
maps the data values with the physical databases.
Note
ERwin supports Integration Definition for Information Modeling (IDEFIX) and
Information Engineering (IE) modeling standards.
Entities represent the identities, physical objects, and other elements, about which
information is stored in the data models. An entity can be a tangible object, such as a book,
or a logical object, such as a business unit. Each entity contains a name, description, and
associated attributes. The values in the attributes identify each element of the entity class.
An independent entity does not require information from another entity to uniquely identify its
content. In contrast, a dependent entity must have information associated with another entity
in the data model. It requires a primary key (PK) value of another entity to identify its
instances uniquely. The database uses this property to identify the instances of entities
stored in tables.
Relationships in a Database
In ERwin, relationships are illustrated using a verb phrase that defines how the two entities
are related to each other and a line that connects the two entities. The identifying
relationships are represented in the logical model and the physical model using one or more
foreign key attributes.
The cardinality of a relationship is the number of child and parent entities related by the
relationship. The degree of a relationship is the number of attributes related to each other in
any two entities. When the degree of a relationship is unary, an instance of the entity is
related to itself. This is also called a recursive relationship. The direction of a relationship
indicates the originating entity in a binary relationship. The originating entity is called the
parent entity and the terminating entity is called the child entity.
ERwin uses a horizontal line to separate the key area that holds the primary key from the
nonkey areas in a data model. The nonkey attributes store the values for the attributes. The
key attributes do not include a Null value and should not be changed randomly. It is
important to avoid any change to a key attribute because all relationships are based on the
values of the key attributes.
The candidate keys in a primary key should be minimum for efficient indexing and data
retrieval. A primary key migrates to the child entities to identify the relationship between the
originating entities and the terminating entities. The migrated primary key of the first entity is
called a foreign key in the second entity. ERwin uses a solid line to represent the identifying
relationships between the parent entity and the child entity. A dashed line in ERwin between
the parent and child relationship indicates a nonidentifying relationship.
The resolution of a database to the first normal form moves the repetitive attributes to
separate entities. A dependent entity that has a set of attributes to represent the redundant
information is created. The resolution of a database to the second normal form removes the
redundant attributes. The attributes that do not have a value for the instances of the entities
are also removed in the second normal form. The resolution to the third normal form relates
all the attributes to the primary key. It terminates the association of the attributes to the other
keys in the data model.
Using ERwin
ERwin enables you to create graphical database models to define relationships.
To modify the database design, you need to change the physical model. ERwin divides large
business data structures and models into smaller models for better manageability. The
Subject Areas are used to hold smaller subsets of the larger data model. ERwin captures
database information through a Data Definition Language (DDL) or the SQL script to
generate the logical model and the physical model.
You can split the models designed by Erwin to apply the business rules into a separate
physical data model and a logical data model. You can then use ERwin to compare the
physical data structures and the data models to identify and resolve any differences. ERwin
has a workspace that contains the Model Explorer, floating toolbars, and a diagram window.
When the model type indicator on the toolbar changes from the logical to the physical or vice
versa, the menu options change appropriately.
ERwin depicts its data models in the logical, physical, or logical/physical modes. In the
physical data model, an entity is represented as a table. The attributes in ERwin are used to
collect information on the entities and columns, which store the values of the attributes in a
physical model.
Model Explorer
The Model explorer provides a text-based hierarchical description of the data model and is
used to edit, navigate, and view the model. The Subject Area pane of the Model explorer
shows a subset of the data model diagram. This is used to divide a complex data model view
into smaller, manageable parts.
The tabs at the bottom of the Model explorer are used to change the pane views. The Main
Subject Area is the default Subject Area and includes all the objects in the data model. Click
the Subset Area icon in the Model explorer to move to the subset pane, as shown in Figure
1-1-1:
The Model explorer is used to create, rename, and delete the attributes and objects in a data
model. It can be used to drag the objects to modify the data model. To copy objects, press
the Ctrl key and drag the object to the new location. Right-click an object to view the context
menu in which the Go To option is used to access an object in the data model. The Delete
option removes an object from the data model and the Properties option opens the
Properties Editor of the objects.
The model type indicator on the ERwin toolbar is used to switch between the logical and
physical models. When the model type indicator is physical, the Model explorer shows only
the physical objects supported by the underlying database.
You can also use the Model explorer to resize objects and move them in the data model.
When the shape of the ERwin pointer resembles a hand, it can be used to move an attribute.
2. In the New Model Type area, click the Logical/ Physical radio button.
3. From the Target Database panel, select the target database and its associated
version.
4. Click OK to open a new data model with a blank diagram window.
The Entity tool adds new entities to the logical data model. To add entities to a data model:
1. Click the Entity tool icon on the ERwin toolbar, as shown in Figure 1-1-3:
2. Click the diagram window to place the entity in the data model.
3. Specify a name for the entity.
4. Click Save on the File menu. The data models are saved in ERwin in files with the
extension, .er1.
Attributes are added to entities to define the data structure, which stores the values in the
physical model. To add attributes to an entity:
1. Place the entity box on the diagram window and name it as Employee.
2. Click the plus sign next to the Entities icon to list all the entities in the data model.
3. Click the plus sign next to the Employee entity in the Model explorer to expand the
object list.
4. Right-click the Attribute icon and select New from the context menu, as shown in
Figure 1-1-4:
Figure 1-1-4: Attribute Context Menu
5. In the Edit textbox, type the name of the new attribute as Emp-NAME. This changes
the data model view in the diagram window to reflect the addition of the Emp-NAME
attribute.
6. Click the Employee entity to select it and press the Tab key.
7. Add a Primary Key attribute, Emp-ID, to the entity. This changes the data model view
in the diagram window to reflect the addition of the Emp_ID attribute, as shown in
Figure 1-1-5:
Setting-up Relationships
The relationships in an ER model show the association between two entities of the data
model. ERwin uses different types of lines to indicate different relationships. A solid line with
black dots near both its heads depicts a many-to-many relationship. A solid line shows the
identifying relationship with a single prominent black dot near the head that terminates at the
child entity. A dashed line depicts a nonidentifying relationship. The lines that indicate
relationships are available in the ERwin Toolbox, as shown in Figure 1-1-6:
5. In the Cardinality pane, click the appropriate radio button to assign cardinality to the
relationship.
6. In the Type pane, click the appropriate radio button to select the relationship type.
The foreign key in the child entity can be assigned an alias name that describes its role in
the child entity. This new name is called a rolename. To assign a rolename to an attribute of
the data model:
1. Right click the relationship in a data model and select the Relationship Properties
option from the context menu.
2. Click the Rolename tab to view the Rolename Info pane, as shown in Figure 1-1-8:
3. From the Migrated Key drop-down list box, select the migrated key to which a role
name must be assigned.
4. Enter the rolename for the migrated key in the Rolename field.
5. Click OK to assign the new rolename to the migrated key.
You can use ERwin to create separate Subject Areas for the logical and physical models.
Each Subject Area is dynamically linked to the data model, which means that any changes in
Subject Area are reflected in the data model. The Subject Area Editor can be used to create,
modify, and delete Subject Areas.
To move to the new Subject Area, click the Subject Area drop-down arrow on the ERwin
Standard toolbar. You can also list the Subject Areas in the Model explorer. Alternatively,
click the Subject Area icon at the bottom of the Model explorer to list all the Subject Areas,
as shown in Figure 1-1-11:
A new Subject Area can also be created in the Model explorer. To create a new Subject
Area from the Model Explorer:
1. Right-click the Subject Area folder and select New from the context menu, as shown in
Figure 1-1-12:
2. Right-click the icon and select New to create a new Subject Area.
3. Assign a name to the new Subject Area.
4. Click the plus sign next to Main Subject Area icon to expand the main Subject Area.
5. Drag-and-drop the entities from the Main Subject Area to add the entities to the new
Subject Area.
A domain is a model object that is used to assign properties to the columns and the
attributes. Domains group attributes together to help reduce the time to develop and
maintain a model. The domains are created using a Domain Dictionary. To create a domain:
1. Select Model -> Domain Dictionary.
2. Click New to open a new domain, as shown in Figure 1-1-13:
Figure 1-1-13: Domain Dictionary
6. Click the button adjacent to the valid field to show the Validation Rules window.
7. Click New in the Validation Rules window to assign the name Between to the validation
rule.
8. Select the validation property type from the Type pane, as shown in Figure 1-1-15:
9. Enter a valid value in the Default field or click the button next to the Default field to
assign a default value to the domain property.
10. Click OK to create the domain.
Presentation Tools
ERwin provides tools to enhance the presentation of the logical and physical data models.
Different colors and shapes can be applied to the data models to show the relationships
between the attributes and the entities.
You can also generate reports about the data models using the ERwin presentation tools.
These reports can be generated in text-based or web-based formats. In addition, the tools
can be used to specify the rules that ERwin uses to map the data types in the physical and
the logical levels of display.
Drawing Features
You can use the drawing features of ERwin to add colors to the data model objects. Drawing
objects with different shapes, such as circles and rectangles, represent an association
between the objects.
You can also use colors to show a relationship between attributes keys. The entity boxes
can be aligned or resized to customize the view of a data model.
To change the font representation and the colors associated with the entities:
1. Open the data model.
2. Select an entity.
3. Right-click the entity and select the Object Font & Color menu option from the context
menu. This opens the Entity Fonts & Colors window, as shown in Figure 1-1-18:
The default fonts and colors can be modified in the data model. These modifications can be
used to apply color standards to identify the keys and the relationships. To change the
default font and color:
1. Right-click the diagram window and select Default Fonts and Colors.
2. Select the font type and size from the Font pane.
3. Select the background color from the Background pane.
4. Select the Relationship tab, as shown in Figure 1-1-19, to apply colors to the lines that
represent the relationships:
Figure 1-1-19: Relationship Tab of the Default Fonts & Colors Dialog Box
5. Select the Entities tab to apply the Fill and Outline colors to the entities.
6. Select the Attributes tab shown in Figure 1-1-20 to apply colors to the Foreign and
Owned keys:
7. Select the Drawing Object Colors tab to modify the Line color and the styles.
8. Select the Drawing Object Text tab to customize the font type and the font size.
Datatype Mapping
Datatype mapping is used by ERwin to map attribute values to the physical schema. It is
feasible to create new datatypes using Erwin, and modify the existing datatypes using the
Datatype Mapping Editor. The Datatype Mapping Editor can be used to specify the
conversion of one dataype to another. To use the Datatype Standards Editor to create the
new physical mapping rules:
1. Select the Start button from the Windows taskbar.
2. Select the ERwin icon and then select ERwin Datatype Standards Editor, as shown in
Figure 1-1-21:
3. Select Mapping -> Insert New Mapping from the Datatype Standards Editor menu.
4. Click the ‘From’ Datatype drop-down to specify the source database.
5. Click the ‘To’ Datatype drop-down to select the datatype to which the source datatype
selected in the ‘From’ Datatype drop-down must be converted, as shown in Figure 1-
1-22:
The new datatype definitions can be created and stored using ERwin. The new datatype is
available in a data model only when the .dsm file, which holds the definition of the new
datatype, is associated with a data model. To create a new datatype definition:
1. Select Tools-> Datatypes-> Edit Datatype Standards.
2. Click a datatype definition in the Datatype column and enter the name Testing.
3. Click the Domain column and select the String domain type from the options.
4. Click the Length column to specify that the length of the string is Optional, as shown in
Figure 1-1-23:
4. Browse the computer to locate the file myDatatype.dsm in the Set Location dialog box.
5. Click the button Set in the Set Location dialog box.
6. Click OK to link the file to the data model.
The Testing datatype defined in the myDatatype.dsm file can be associated with an attribute
of the current data model. To associate the Testing datatype with an attribute:
1. Open the data model.
2. Click the plus sign next to the attribute icon to expand the list of all the attributes.
3. Select the attribute to which the data definition Testing is to be applied.
4. Right-click the attribute and select Properties from the context menu.
5. Click the Datatype tab and select the data definition Testing in the Datatype option list,
as shown in Figure 1-1-25:
You use the Report Template Builder (RTB) wizard to build reports. You can select an
existing template and use the Edit button on the Reports Template wizards, as shown in
Figure 1-1-26:
The Output Type drop-down list on the Reports Template window is used to set the output
type from the available options of HTML, Text, and Rich Text Format (RTF). To generate a
report Run button must be clicked.
6. Click the Title, Header, and Footer tabs to add them to the report.
7. Click the Definition tab to add a definition to the report.
8. To apply the Attribute section to the report, click the Right arrow to select the Attribute
icon in the Logical tree, as shown in Figure 1-1-27.
9. Right-click the Attribute section line and select Properties to open the Properties
window.
10. Click the plus sign next to Attribute icon to list all the attributes.
11. Select the check box for the object that must be included in the report.
12. Click the Section tab to name the section, assign foreground and background colors,
and to set the font type and the font size.
13. Click the Export tab to verify that HTML is the export option in the Export As list.
14. Close the window to see the changes applied to the section.
15. Apply the Relationship section to the report and customize the objects to be included.
16. Click the Run button on the Report Generator, as shown in Figure 1-1-28, to generate
the HTML report. ERwin automatically opens the Web browser to show the report
page to the end user:
Figure 1-1-28: Report Template Builder Buttons
Naming conventions play an important role in data model development. Assigning random
names to data model objects can cause ambiguity. The rules, such as Prefix Qualifies and
Suffix Clarifies, are used to standardize the naming conventions. ERwin provides built-in
tools used to apply naming conventions to the elements of a data model.
ERwin uses the process of Forward engineering to automatically generate the physical
schema on a relational database system based on a data model. After a physical schema is
generated from the data model, ERwin creates the parent storage data structure and then
the child storage data structures. ERwin can also be used to Reverse engineer a database.
In Reverse engineering, ERwin imports the scripts, which define the physical schema to
create the data models that correspond to the schema.
Over time, the structure of a data model is altered to accommodate the dynamic nature of
database management systems. The physical model of ERwin cannot track the changes
made to the physical implementation of the data model. Any alterations to the physical
schema of the storage objects can cause the data model to differ from the storage object
implementations. The features of ERwin can be used to identify these differences and to
resolve them.
ERwin uses a three-tier approach to layer the database design procedure. The first layer can
be used to capture the requirements of the business rules. This layer is represented using
the logical model. The second layer is the physical layer. It is a visual abstract of the physical
implementation of the data model and is represented using the physical model. The third
layer is the process of Forward engineering where the physical model is applied to a
relational database management system to create physical storage objects in the physical
schema.
ERwin supports the splitting of a Logical/Physical model into two separate models - a logical
model and a physical model. To split a Logical/Physical model:
1. Select File > Open to open the Logical/Physical data model.
2. Browse the computer to locate the data model.
3. Select the Tools menu from the ERwin toolbar.
4. Select the menu option Split L/P model menu option.
5. Type the name of the Logical model when the Split Model/Logical- Save As dialog box
appears.
6. Type the name of the Physical model when the Split Model/Physical- Save As dialog
box appears.
To support the reuse of data models, Erwin creates a new data model from an existing one.
The new data model objects are linked to the original data model. To derive a new data
model from an existing data model:
1. Select File > Open to open the original data model from which the new data model
must be derived.
2. Select the Tools menu from the ERwin toolbar.
3. Select Derive New Model from the Tools menu to open the Derive New Model wizard.
4. Select the Logical, Physical, or Logical/Physical radio button from the New Model Type
pane.
5. Click Browse File System to locate the template from which the new model must be
derived.
6. Select the database type and version from the Target Database pane.
7. Click Next to view the Derive Models–Select Source Model Objects window, as shown
in Figure 1-1-29:
8. To select the objects from the source model that must be included in the derived
model, select the check boxes next to the objects listed.
9. Click Next to view the Logical to Physical Name Conversion window to accept the
default naming standards.
10. Click Finish to derive a new data model.
The database physical schema can be further layered to improve the performance of the
data model. Transformations are applied to normalize the data model. Normalization
increases the efficiency of an RDMBS implementation. The source objects in transformation
are the storage objects on which the transformation is applied. The target objects are the
entities and attributes created when the transformation is applied to the source object. The
new entities and attributes add a design layer that improves the performance of the
database. The transformations applied using ERwin are available on the Transformation
toolbar.
To apply a many-to-many transformation that dissolves the relationship and adds additional
entities to the data model:
1. Open the Logical data model.
2. Click the Relationship line that links two entities.
3. Click the Many-to-Many Transform button on the Transformation toolbar to open the
Many-to-Many relationship transform wizard.
4. Click Next to specify the table name and add comments to the transformation.
5. Click Next to give a name and add a definition to the transformation.
6. Click Next to view a summary of the transformation, as shown in Figure 1-1-30:
Figure 1-1-30: Summary-Many-to-Many Transformation Wizard
To delete a transformation:
1. Open the data model.
2. Click the plus sign next to the Transformation icon to view all the transformations.
3. Right-click the transformation to be deleted.
4. Select Delete to delete the transformation. This activity depicts the Resolve
Transformation or Reverse Transformation options shown in Figure 1-1-31. When a
transformation is reversed, it deletes the newly created entities. When a
transformation is resolved, it retains the new layers but removes the source entity.
To use the Model Naming Options Editor to apply the naming standards to a data model:
1. Open the data model.
2. Select Tools -> Names -> Model Naming Options.
3. Click the Logical tab to specify the Case and Maximum length rules for logical objects.
4. Click the Physical tab to specify the Case and Maximum length rules for objects.
5. Click the Name Mapping tab shown in Figure 1-1-32:
6. In the Abbreviation Type column, specify the suffix or prefix to be used to apply to the
names.
7. Click the Duplicate Names tab to specify the rules that influence how ERwin should
handle the duplicate names, as shown in Figure 1-1-33:
Figure 1-1-33: Duplicate Names Tab-Model Naming Options
3. Select the View option in the Schema Generation window to customize the view
scripts.
4. Select the checkboxes next to the options in the View listing.
5. Select Table to customize the Table options.
6. Select Column to customize the Column options.
7. Select the Index option shown in Figure 1-1-34 to customize the creation of the index
or to drop the index based on the keys.
8. Select the Trigger option to specify the generation of ERwin Generated or User-
Defined triggers.
9. Select the Others option to specify the information, such as the owner names and
comments.
10. Click the Filter button to view the Select window for filtering the entities on which
Forward engineering must be applied, as shown in Figure 1-1-35:
11. Click the Preview button shown in Figure 1-1-35 to view the listing generated.
12. Click the Print button to take a hard copy of the schema generation.
13. Click the Generate button to implement the physical schema to the database
management system.
Reverse engineering is the process of generating a data model based on a DDL or a SQL
script file. The data model can be used to refine the database physical schema by including
new storage objects and defining new layers. It can also be used to apply transformations to
normalize the tables. To carry out Reverse engineering:
1. Open the Logical, Physical, or the Logical/Physical data model.
2. Select Tools -> Reverse Engineer to open the Select Template screen, as shown in
Figure 1-1-36:
3. Browse the file system to select the template that must be associated to generate the
data model.
4. Select the Target Database and its Version.
5. Click Next to view the Set Options window.
6. Choose the Script radio button in the Reverse Engineering From pane to specify the
script file from which the data model must be generated.
7. Select the check boxes that must be included in the data model from the Items to
Reverse Engineer pane.
8. Click Next to generate the data model.
Complete Compare
The Complete Compare feature of ERwin enables you to synchronize the physical and
logical data models. This feature can also be used to specify how the difference in the two
models must be resolved. The import option is used to change the current data model to
resolve the difference between the two models. The export option can be used to apply the
changes to the linked data model. The comparisons can be performed at the database level
or the model level. When the comparison is performed at the database level, it can be
achieved with an existing database or a script file.
7. Click Next to show the Object Filter Option to specify the objects on the two models
that must be compared.
8. Click Next to specify how the differences between the two models must be resolved
from the Resolve Differences screen shown in Figure 1-1-38:
In addition to its design tools, AllFusion ERwin Data Modeler includes database
development tools that automatically generate code for tables, stored procedures, and
triggers. You can use macros to quickly generate database designs. These macros can be
used in trigger templates, stored procedures, and scripts. This means that any Database
Management Systems (DBMS) that supports macros can utilize the designs or templates
created in AllFusion ERwin Data Modeler.
This ReferencePoint describes AllFusion ERwin Data Modeler and explains how to use
macros and trigger templates to generate database designs. In addition, this ReferencePoint
describes how to customize triggers and stored procedures to manage large models using
AllFusion ERwin Data Modeler.
The reference information for each macro is divided into the following components:
Description: Provides the explanation and use of a specific type of AllFusion ERwin
Data Modeler macro.
Macro syntax: Provides the syntax for each AllFusion ERwin Data Modeler macro.
Scope of the macro: Specifies the commands in which the macro can be included. This
scope checks whether the macro can be used in a conditional %If statement or in the
template types in which the macro is included. Table 1-2-1 lists the various macro
scopes with their corresponding template types:
Table 1-2-1: Macro Scopes and Corresponding Template Types
In addition to the macros used with AllFusion ERwin Data Modeler objects, there are certain
miscellaneous macros that return the logical or physical database names.
For example, you use the %+ macro to add macro codes within the %+ macro. The syntax
for the %+ macros is:
%+(<macro code1>,<macro code2>)
The above expanded code is the result of the template code of the %+ macro.
Variables Used in Macros
The common variables used in macro syntax commands are:
<value>, <default value>, and <initial value>: Represent a text or number defined by
you that appear similar to the expanded code of the macro.
<action>: Represents a valid SQL action, such as Insert, Update, or Delete.
<function>: Represents a function name of the program or subprogram that can be
called to perform an action.
<macro code>,<macro code1>,...,<macro code n>: Represents a macro code
sequence that is valid in the current scope. Multiple macro code sequences included in
the same command are numbered from 1 to n.
<predicate>: Represents any valid Boolean expression that evaluates to True or False.
This includes the expressions supported directly by an AllFusion ERwin Data Modeler
macro, such as %AttIsFK, and those created using supported Boolean operators, such
as %!=, and other comparison operators, such as %And, %Or, and %Not.
<prefix>, <old prefix>, and <new prefix>: Represent a text or numeric value, such as
@ins, or an expanded macro, such as %Parent, that is added to the beginning of a
table or column name when the macro code is expanded. If both the old and new prefix
elements are specified, the list created by the macro contains two sections. The first
declares <old prefix> <element> and the second declares <new prefix> <element>.
<separator>: Represents one or more characters used to delimit a list created by the
macro. Separators are defined by quotation marks, such as "OR".
<table name>, <default name>, <domain name>, and <validation>: Are replaced by
the name of an AllFusion ERwin Data Modeler table, default, domain, or validation rule
or the corresponding macro, such as %TableName, %Child, %DefaultName,
%DomainName, and %ValidationName.
<variable>: Represents the name used within the template.
3. Click the Macro Toolbox button to open the Macro Toolbox dialog box, as shown in
Figure 1-2-2:
AllFusion ERwin Data Modeler supports RI triggers, which are triggers that maintain the
integrity between two related tables. For example, if a row in a parent table is inserted,
updated, or deleted, an RI trigger informs the DBMS what to do to rows in other tables that
have a foreign key value that matches the primary key in the row being added, updated, or
deleted.
AllFusion ERwin Data Modeler provides a set of default RI trigger templates that are
attached to tables to inform the target database server how to enforce RI. You can use
AllFusion ERwin Data Modeler macros to customize the RI trigger templates and override
the default code generated.
The syntax to use the %Include macro for the trigger template is:
%Include (<trigger template name>)
The above syntax includes three parameters, the trigger action, RI type, and integrity rule.
In the above expanded code, Is rented under is the phrase generated by the server through
%VerbPhrase.
Each default trigger template includes text, SQL code, and macros that are applied on any
table or relationship in a model. During schema generation, AllFusion ERwin Data Modeler
expands the macros into physical table, column, and relationship names. Each macro
derives its value based on the relationship to which the template is attached.
The default trigger template generates the Create Trigger statements for all the tables in the
database because AllFusion ERwin Data Modeler uses macros instead of a specific table
and relationship. For example, if an insert trigger is added to a model or table, the model
automatically generates a code for the Insert trigger using macros for all the tables.
Listing 1-2-1 shows the template code for the INSERT trigger:
The above listing shows the expanded code of an Insert trigger added to the Movie_Detail
table.
For example, in a database that stores purchase orders, you may want to flag backorder
items when creating a row in the Cust_Order table, which stores customer information. To
do this, you can create a custom trigger to check the quantity_on_hand value for a product
when inserting a row into the Order_Line table, which stores the information pertaining to the
orders received.
AllFusion ERwin Data Modeler triggers can effectively handle the most common rules, such
as rules to insert, update, or delete table values to enforce RI, without any additional
programming or customization.
The default triggers do not fully implement all the business rules on a table, relationship, or
RI action. You can customize a trigger template by changing the default RI trigger or by
creating a table to override the trigger template. Each macro derives its value based on the
relationship to which the template is attached. You can define the background for macro
expansion by attaching a template to a table that is either the parent or child table in a
relationship.
For example, a video library uses a database that includes various tables related to videos.
In the database, the Movie_Copy is the child table of the Movie table, which stores the movie
information in the library and the Movie_Copy table stores information pertaining to the
movies currently rented out. An AllFusion ERwin Data Modeler model contains a relationship
between the Movie and Movie_Copy tables, such as Movie_is_rented_as_Movie_Copy.
AllFusion ERwin Data Modeler expands the macros in the trigger template during schema
generation as follows:
Each time AllFusion ERwin Data Modeler finds the %Parent macro, it replaces the
parent table name with Movie.
Each time AllFusion ERwin Data Modeler finds the %VerbPhrase macro, it replaces
the verb phrase with is_rented_as.
Each time AllFusion ERwin Data Modeler finds the %Child macro, it replaces the child
table name with Movie_Copy in the relationship.
You can specify or change default RI rules in the specified model. To specify default RI
rules:
1. Click -> Model -> Model Properties. The Model Properties dialog box opens, as shown
in Figure 1-2-3:
Figure 1-2-3: The Model Properties Dialog Box
Figure 1-2-5 shows the RI Override trigger template to be modified in the SQL Server
Trigger Templates dialog box:
2. From the User Override List, select the trigger template name that needs to be
modified.
3. Add code or text in the Template Code box or insert a macro using the Macro Toolbox.
4. Type the parameter name in the inserted macro.
5. In the Template Name box, specify a name for the template and click Add to create a
template or save the template using a different name.
6. Click Close.
The above listing shows the override template code for the Child Delete Cascade trigger.
This trigger template ensures that if a row is deleted in the child table, the status attribute of
the parent table is updated with a message that a row from the child table has been deleted.
Listing 1-2-4 shows the expanded code for the Child Delete Cascade trigger for SQL Server:
Listing 1-2-4: Expanded Code for the Child Delete Cascade trigger
The above code shows the expanded code for the Child Delete Cascade trigger for the
Movie_Copy table.
You can create a stored procedure and include it in the schema generation scripts. AllFusion
ERwin Data Modeler expands any template code in the stored procedure. It includes the
Create Procedure statement for each procedure attached to a table, view, or model while
generating the schema.
You can drop a previously defined stored procedure AllFusion ERwin Data Modeler runs a
Drop statement for each Create Procedure statement in the generated schema.
AllFusion ERwin Data Modeler does not support built-in stored procedure templates because
there are no standard functions provided by a stored procedure. To work with stored
procedures, you need to use the following windows and dialog boxes:
The Stored Procedure dialog box: Used to add, change, and delete stored procedures
for models, tables, or views.
The Stored Procedure browser window: Used to attach, detach, and manage stored
procedures and the tables or views that you attach to these.
You need to make a note of the order in which the stored procedures are added. This is
because AllFusion ERwin Data Modeler generates the stored procedure code based on the
order in which the procedures are displayed in the Stored Procedure dialog box. You can
change this order, if necessary.
3. Click the Browser button to select the Stored Procedure template to be attached. The
Stored Procedure Browser dialog box appears, as shown in Figure 1-2-8, where
stored procedure templates are attached to tables and views:
Figure 1-2-8: The Stored Procedure Browser Dialog Box
4. From the SP Template Name list box, select the stored procedure to be attached.
5. From the Unattached Table list box, select the table or view name.
6. Click the Attach button to attach the selected procedure to the selected table or view.
7. Click Close and then click OK.
4. From the SP Template Name list box, select the stored procedure.
5. From the Attached Table list box, select the table or view from which the stored
procedure needs to be detached.
6. Click the Detach button to add the selected table or view name to the Unattached
Table list box.
7. Click Close and then click OK.
Figure 1-2-10: The Code Tab in the Stored Procedures Dialog Box
3. From the Stored Procedure list box, select the stored procedure.
4. Click the Code tab and change the code in the Code box or insert a macro from the
Macro Toolbox.
5. Click OK.
Figure 1-2-11: The Delete Button in the Stored Procedures Dialog Box
3. From the Table combo box, select a table name for the table-level stored procedure.
4. From the Stored Procedure list box, select the stored procedure to delete.
5. Click Delete and then click OK.
Figure 1-2-12: The Stored Procedures Dialog Box with Controls to Change the
Order of Generation
3. From the Stored Procedure list box, select the stored procedure for which you need to
change the order of generation.
4. Click the Up or Down buttons to change the order of generation for the selected stored
procedure to before or after other stored procedures, respectively.
5. Click OK.
While changing server-specific code to migrate a stored procedure, you do not need to
update the table and attribute names, and data type information related to the stored
procedure if they are referred to with macros. AllFusion ERwin Data Modeler automatically
converts the table and attribute names, and relationship information represented by the
macros for the selected target database server.
If you declare the macro variables at the beginning of the stored procedure, the values
assigned to these variables remain constant. Use the %Decl macro to declare a variable, the
%=<variable> macro to assign a value to it, and the %: macro to expand the variable during
generation.
Other report-specific features provided by the ERWin data modeler include the report search
and the data movement rule features. The report search feature of the ERWin data modeler
enables you to search a specific object in a report. The data movement rule feature of
ERWin includes the rules to maintain and update tables regularly. You use the Data
Movement Rule dialog box to define rules for updating model tables.
This ReferencePoint describes how to generate and maintain reports using Report Template
Builder and ERWin Data Browser. It also explains data movement rules in ERWin.
This ReferencePoint uses the Toy Universe model as a sample model to create reports. This
model contains information related to toys for sale and other information about orders for
manufacturing, purchasing, or selling toys. This model also tracks the delivery status of an
order.
The report templates that enable you to generate reports in RTF are:
RTF Entity Primary Key.rtb: Lists the tables and corresponding primary keys in the
model.
RTF Physical Only Columns.rtb: Lists the columns of the physical model.
RTF Relationship Phrase Report.rtb: Lists the relationship phrases of the model.
Relationship phrases describe the relationships between child and parent objects in the
model.
Text reports generate Comma Separated Values (CSVs) when you select either RTF or the
text format to generate the report template. The report templates that enable you to generate
reports in the text format are:
CSV Attribute Names.rtb: Creates a comma delimited text file of the attributes included
in the model.
CSV Column Names.rtb: Creates a comma delimited text file of the columns included
in the model.
CSV Domain Names.rtb: Creates a comma delimited text file of the domains in the
model.
CSV Entity Names.rtb: Creates a comma delimited text file of the entities in the model.
CSV Table Names.rtb: Creates a comma-delimited text file of the tables in the model.
In addition to these report templates, you can generate a Model Validation report that checks
for the consistency of the designed database model. The Report Editor, which you use to
edit reports in the ERWin data modeler, provides the Model Validation option for both logical
and physical Model Validation reports. The Model Validation report generates errors in the
model before converting the model to a database. To generate a Model Validation report:
1. Click Start-> Programs-> Computer Associates-> AllFusion-> ERWin Data Modeler->
ERWin to open the ERWin data modeler.
2. Click Tools-> Report Builder-> Report Builder. The Report Templates dialog box
appears, as shown in Figure 1-3-2:
Figure 1-3-2: The Report Templates Dialog Box
3. Double-click Document Untitled in the Report Layout frame. The Properties window
appears.
4. Select the Property Tree tab and select a format from the displayed list to generate the
standard template.
5. Select the Title tab to display the options used to change the title of the model.
6. Close the Properties window to return to the Report Template Builder window.
7. Select an object from the Available Sections pane of the Report Template Builder
window.
8. Click the forward button between Available Sections and Report Layout to add the
selected section to the report. For example, select Table from the physical hierarchy
and add it to the report.
Figure 1-3-6 shows the Table section added to the Report Layout section:
Figure 1-3-6: The Table Section Added to the Report Layout Section
9. Double-click the Table section to modify its properties. The Properties window
appears.
In the Report Template Builder window, click Edit-> Preferences to modify the format
of the template. The Report Template Builder Preferences window appears, as
shown in Figure 1-3-8:
10. Select the Title tab of the Report Template Builder Preferences window to change the
title name and format.
11. Click OK to close the Preferences window.
12. Click File-> Save to save the created report template.
Figure 1-3-9 shows the Report Template Builder window with a standard template
created:
Figure 1-3-10 shows the output of the report template after running it on a Web
browser:
4. Click the Table section to show the list of tables and their attributes in the right frame.
Figure 1-3-12 shows the Report Templates dialog box with a template selected for
editing:
Table 1-3-1 lists the various report formats and the corresponding report files generated
when you run the report:
Table 1-3-1: Report Formats and Corresponding Report Files Generated
Report Format Generated Report File(s)
Figure 1-3-13 shows Report Template Builder with the Picture section:
4. Double-click the Picture section to access its properties. The Properties window opens.
5. Make the required changes to the properties of the Picture section.
6. Run the report template.
7. Click the Picture section to view the picture in the left frame of the Web page.
Importing a Report
You can import a report in Report Builder to send information across the ERWin data
modeler. To import reports in Report Builder:
1. Open Report Builder.
2. Select the report with the .erp extension. If the Available Templates list box does not
list the report, click Browse to select the folder that contains the required file.
3. Click OK to close the Browse for Folder dialog box and list the report files in the Report
Templates dialog box.
Figure 1-3-16 shows the Report Templates dialog box with a list of .erp reports in the
selected folder:
Figure 1-3-16: The Report Templates Dialog Box with a List of .erp Reports
6. Select the components that you need to import from the Select component(s) for
import list box.
7. Click OK to close the Import from ERP dialog box and open Report Template Builder to
view the imported report.
Using Data Browser
The Data Browser provides built-in report categories for ERWin models. Each category
consists of a set of options that you can include in or exclude from reports. It also provides
predefined sorting and filtering options to display a sorted report.
The Report folder stores a report created in the Data Browser. It adds a Result Set icon in
front of all the reports in the Report folder. This icon specifies that the values have been
added to the report. A result set is a set of values added to the created report. You can
modify the content and appearance of a report using the Data Browser Properties window.
You can search specific information in the result set of the created report in the Data
Browser. The result of this search is in the form of a string, an integer, or dates for multiple
columns in the result set.
3. Click File-> New ERWin Report. The Reports dialog box appears, as shown in Figure
1-3-19:
4. Deselect the Table Column Name attribute from the Column section in the Column
Options tab.
5. Click OK to close the Report Format dialog box.
4. Select Table Column Name from the Column list box of the Find in Result Set dialog
box.
5. Type Description in the String Expression list box.
6. Click Find All to start the search and obtain the output in the Find in Result Set
window.
Exporting Reports
The output of the report generated in Data Browser is within the Data Browser window in a
specific format. To obtain this output in another format, such as HTML or text, you can
export the generated report from the Data Browser to the desired format. To export the
generated report to another file format:
1. Open the Data Browser window.
2. Click File-> Export. The Export from Data Browser dialog box appears, as shown in
Figure 1-3-25:
3. Select the desired file format from the Export format drop-down list box. For example,
to export the ToyUniverse report to an HTML file, select the HTML format from the
Export format drop-down list box.
4. Select the presentation style from the Presentation section.
5. Select an option from the Export to section to export the report to either a file or a
clipboard.
6. Click Export to export the report in the selected format.
Importing Reports
You can import reports from other formats to the Data Browser. To import a report to the
Data Browser:
1. Open the Data Browser window.
2. Click File-> Import. The Import to Data Browser dialog box appears, as shown in
Figure 1-3-27:
Figure 1-3-27: The Import to Data Browser Dialog Box
3. Select the file format from the Import source drop-down list box.
4. Click Import. The Open dialog box appears.
5. Select the source file and click Open to add the selected report to the Data Browser
window.
Data Movement Rules in ERWin
Data movement rules in the ERWin Data Modeler enable you to maintain processes required
to regularly update all tables in the model. The Data Movement Rule dialog box stores the
processes required to update information. You must have available data storage that stores
information from various Online Transaction Processing (OLTP) systems.
You should know the source of this information and how and when to update this
information. To store this information, you can use various ERWin dialog boxes, such as the
Data Warehouse Source dialog box, which stores the source of information, the Columns
dialog box that stores information about each column, and the Data Movement Rule dialog
box. The various management rules used to manage the information supported by ERWin
are:
Refresh: Replaces existing data.
Append: Updates the existing information with changes and additional information.
Backup: Creates a copy of the information to make it available for recovery.
Recovery: Stores information from the backup information, the recovery process is
required when the data is lost due to hardware or network failure.
Archiving: Extracts information from tables based on criteria and saves the information
in a file for future reference.
Purge: Extracts information based on criteria but does not save the information.
2. Select the Data Movement check box in the General tabbed page.
3. Click OK to close the Model Properties dialog box.
3. Click an empty cell in the Rule Name column and type a rule name.
4. Click an empty cell in the Type column to open the Rule combo box.
5. Select a rule from the Rule combo box.
6. Type a description of the rule in the Definition text box.
7. Click OK to close the Data Movement Rules dialog box.
Figure 1-3-30 shows the contents of the Attachment tabbed page in the Data
Movement Rules dialog box:
Figure 1-3-30: The Attachment Tab in the Data Movement Rules Dialog Box
3. Double-click the table name in the Unattached Tables list to add the table to the
Attached Tables list. Alternatively, you can select the table and click Add to add the
table to the Attached Tables list or click the Add All button to add all the tables to the
Attached Tables list.
4. Click OK to close the Data Movement Rules dialog box.
Figure 1-3-31 shows the Data Movement Rules dialog box with the Delete button:
Figure 1-3-31: The Delete Button in the Data Movement Rules Dialog Box