Using ERwin Data Modeler

46
Point 1: Using ERwin Data Modeler for Optimal 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. Data Modeling Concepts Data modeling enables you to formulate information structures and capture business rules. Data structures are defined to store the data associated with a data model. These structures provide a description for the information that flows in a data model. The graphical representation of a data model depicts the relationships between the storage data structures. 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 and Attributes Attributes are used to apply the business rules to a data model. The values stored in the attributes identify the characteristics of an entity. 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. In ERwin, an entity is the graphical representation of logically grouped data. It represents a class that consists of data and data structures. The ER diagram provides a visual representation of relationships among the entities in a data model. In these diagrams, an entity is represented by a rectangular box. 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. The key attributes are: Primary Key: Defines a single attribute or a set of attributes to identify the instances of entities. All relationships in a data model are based on primary keys. Domain experts

description

data modeling with erwin

Transcript of Using ERwin Data Modeler

Page 1: Using ERwin Data Modeler

Point 1: Using ERwin Data Modeler for Optimal 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.

Data Modeling Concepts

Data modeling enables you to formulate information structures and capture business rules. Data structures are defined to store the data associated with a data model. These structures provide a description for the information that flows in a data model. The graphical representation of a data model depicts the relationships between the storage data structures.

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 and Attributes

Attributes are used to apply the business rules to a data model. The values stored in the attributes identify the characteristics of an entity.

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.

In ERwin, an entity is the graphical representation of logically grouped data. It represents a class that consists of data and data structures. The ER diagram provides a visual representation of relationships among the entities in a data model. In these diagrams, an entity is represented by a rectangular box.

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.

The key attributes are: � Primary Key: Defines a single attribute or a set of attributes to identify the instances of

entities. All relationships in a data model are based on primary keys. Domain experts

Page 2: Using ERwin Data Modeler

help identify a primary key and discover its attributes. Each key attribute is called a candidate key.

� Simple: Defines an attribute that has been reduced to its smallest possible granularity and is completely dependent on the primary key for values. Each simple attribute must have a value.

� Derived: Defines an attribute derived from the values of one or more attributes. These attributes are dependent on other attributes in the data model for their values.

� Foreign Key (FK): Defines a single attribute or a set of attributes that are primary keys for another entity. These are the key attributes that migrate to another entity in a data model.

The different types of entities are: � Core: Describes the entities in a data model on which the business rules are applied.

The core entities are also called the primal entities. They can be dependent or independent. The core entities identify the entity classes that can be reused in a data model. All core entities are extensively reused to implement standardization, reduce implementation time, and minimize changes or errors.

� Code: Describes independent entities. They are also called reference entities. The values assigned to the attributes of the code entities identify unique instances of the record values in a database.

� Subtype: Describes dependent entities. They are used to store a different set of attributes for the same entity. The siblings of the subtype entity are related to their parents using an inclusive or exclusive relationship.

� Associative: Describes the entities that have primary keys that are composite and consist of values from two or more entities. These entities help resolve a many-to-many relationship in which many instances of one entity are related to many instances of another entity.

� Redundant: Describes the entities that have different names but contain information on the same object. These entities are used when a role is modeled for an entity.

� Overloaded: Describes the entities that contain information on multiple objects in a data model. These entities do not have values for each of their attributes.

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.

The different types of relationships are: � Identifying: Defines a relationship that identifies instances of child entities based on the

values of the attributes in a parent entity. The child entity is dependent on the parent entity.

� Subtype: Defines a relationship that relates a parent entity to one or more child entities. This type of relationship identifies one or more instances of an attribute set in the child entities. If there is only one child entity, the relationship is called exclusive. In case there is more than one child entity, the relationship is called inclusive.

Page 3: Using ERwin Data Modeler

� One-to-One: Defines a relationship that relates a single instance of one entity with a single instance of a second entity. The parent and child entities are related using a primary key to identify instances of the attribute values.

� One-to-Many: Defines a relationship that relates a single instance of one entity to many instances in the second entity. The instances of the second entity are identified using composite keys.

� Many-to-Many: Defines a relationship that relates a single instance of one entity to many instances in the second entity, and a single instance of the second entity to many instances of the first entity. These relationships are resolved using the composite keys and the associate keys of the parent entity.

Designing Key Constraints

Key constraints are designed to uniquely identify the instances of entities. This is done after all the data structures required to store the data are defined. The constraints are also used to restrict the range of values that attributes can take.

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.

Tuning Database Models

The process of normalization defines the way in which the attributes in an entity are related to each other and to the primary key. Normalization can be used to fine-tune the database models. It minimizes the redundancy of information in a database, which in turn minimizes ambiguities. Null values also waste the memory allocation for database records and result in identity conflicts when the data is retrieved.

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

Page 4: Using ERwin Data Modeler

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:

Figure 1-1-1: Model Explorer

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.

Creating a Data Model

You can create a new data model in ERwin by using an existing template or opening a blank template. You can create a logical model, a physical model, or a Logical/Physical model.

Page 5: Using ERwin Data Modeler

To create a new Logical/Physical model: 1. On the File menu, click New to view the Create Model-Select Template dialog box, as

shown in Figure 1-1-2:

Figure 1-1-2: The Create Model-Select Template Dialog Box

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:

Figure 1-1-3: Entity Tool Icon on the ERwin Toolbar

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:

Page 6: Using ERwin Data Modeler

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:

Figure 1-1-5: Adding Attributes

8. Press Enter to add another Primary Key attribute. 9. Press Tab to add the nonprimary attributes to the entity.

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:

Figure 1-1-6: Toolbox Buttons

To define a relationship between two entities: 1. From the ERwin toolbar, select the type of relationship to be applied. 2. Click the parent entity. 3. Click the child entity. The primary key of the parent entity automatically gets

propagated as the foreign key of the child to identify the relationships. 4. Right-click the relationship line that connects the two entities. Select Relationship

Properties from the context menu to open the Relationships dialog box, as shown in Figure 1-1-7:

Page 7: Using ERwin Data Modeler

Figure 1-1-7: Relationships Dialog Box

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:

Figure 1-1-8: Rolename Tab

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.

Using Subject Areas and Domains

You can use ERwin to apply the top-down approach to develop data models. Large data models can be divided into small parts to simplify data modeling. The Subject Area in ERwin contains a subset of objects that exist in a data model. The main Subject Area is the default Subject Area that holds all the objects in a data model.

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 create a Subject Area: 1. On the ERwin Standard toolbar, click the Subject Area Editor button as shown in

Figure 1-1-9:

Figure 1-1-9: Subject Area Editor Button

Page 8: Using ERwin Data Modeler

2. Click New to assign a name to the Subject Area. 3. Click the Members tab to select the members to be included in the Subject Area, as

shown in Figure 1-1-10:

Figure 1-1-10: Members Tab-Subject Area

4. Click OK to create a new Subject Area.

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:

Figure 1-1-11: Subject Areas Pane

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:

Figure 1-1-12: Subject Area Icon - Model Explorer

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:

Page 9: Using ERwin Data Modeler

Figure 1-1-13: Domain Dictionary

3. Click New to create a new domain in the data model. 4. Assign a name for the new domain. 5. Select the Datatype tab in the logical model or the Database tab in the physical model

to assign the datatype domain property, as shown in Figure 1-1-14:

Figure 1-1-14: Datatype Tab – 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:

Figure 1-1-15: Validation Rules Window

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.

To assign a domain property to the Employ-ID field: 1. In the Model explorer, right-click the Employ-ID icon to select the Properties option

from the context menu. 2. Click the Datatype tab to assign a datatype to the attribute. 3. Assign the validation rule, Between, from the Valid drop-down list, as shown in Figure

1-1-16:

Figure 1-1-16: Assigning Validation Rules

4. Click OK to apply the domain property, Between, to the Employ-ID field.

Presentation Tools

Page 10: Using ERwin Data Modeler

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 align objects in a data model: 1. Open the data model and select the entities to be aligned in the data model. 2. From the Alignment tab, select the appropriate alignment button to align the objects, as

shown in Figure 1-1-17:

Figure 1-1-17: Alignment Tab

3. Click the Group button to group the selected entities together.

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:

Figure 1-1-18: Entity Fonts & Colors Window

4. Customize the Font type and size in the Name pane. 5. Customize the Fill and Outline color from the Box pane. 6. Click OK to apply the changes.

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.

Page 11: Using ERwin Data Modeler

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:

Figure 1-1-20: Attributes Tab-Default Font & Colors

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:

Figure 1-1-21: ERwin Datatype Standards Editor

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:

Figure 1-1-22: ‘To’ Datatype Pull-down

Page 12: Using ERwin Data Modeler

6. Click the File and Save As menu option to save the datatypes definition file.

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:

Figure 1-1-23: Datatype Length Definition-Datatype Standards Editor

5. Enter a numeric value in the Default Length column. 6. Select File-> Save As from the ERwin Datatype Standards Editor. 7. Specify the file name as myDatatype.

To link the file myDatatype.dsm to a data model: 1. Open the data model. 2. Select Tools-> Datatypes-> Model Datatype Options. 3. Click the Use File radio button, as shown in Figure 1-1-24:

Figure 1-1-24: Associating a Datatype File

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:

Figure 1-1-25: Associating Datatype with Attribute

6. Click OK to associate the Testing datatype with the attribute.

Page 13: Using ERwin Data Modeler

Model Report Generation

It is possible to generate reports using ERwin tools to list the features of the data models. The reports can be generated based on built-in formats or by defining new report formats. These reports can be produced in text formats or Web-compatible HTML formats.

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:

Figure 1-1-26: Report Templates Window

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.

To generate a customized report using the Report Builder tool: 1. Open the data model for which the report is to be generated. 2. Click the Report Template Builder icon on the Standard toolbar. 3. Click the Output Type drop-down list to set the type to HTML. 4. Click New to open the Report Layout screen. 5. Right-click the Document Untitled bar and select Properties from the context menu to

view the Properties window, as shown in Figure 1-1-27:

Figure 1-1-27: Adding Attribute Section–Report Template Builder

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:

Page 14: Using ERwin Data Modeler

Figure 1-1-28: Report Template Builder Buttons

Advanced ERwin Features

ERwin uses ER diagrams to present an abstract of a data model. It divides data modeling into multiple layers to apply the business rules to the data model. Each layer defines a set of rules that influence a category of decision in data modeling. In a layered architecture, a complex implementation can be divided into more than one layer to facilitate development. ERwin supports layered architecture design features such as the Split model and the Synchronize model to derive new models.

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.

Layering a Data Model

Database design and data modeling can be divided into layers to facilitate the development of a data model. Both, the physical and the logical data models must be developed for each layer of data modeling.

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.

Page 15: Using ERwin Data Modeler

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:

Figure 1-1-29: Derive Models–Select Source Model Object

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:

Page 16: Using ERwin Data Modeler

Figure 1-1-30: Summary-Many-to-Many Transformation Wizard

7. Click Finish to apply the transformation.

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.

Figure 1-1-31: Deleting Transformation

Standardizing Names in a Data Model

You can use built-in tools used to apply naming conventions to standardize the names applied to the attributes and the entities in the data model. A good naming standard helps to describe the roles of the attributes and the entities in the data model. Naming standards can be used to resolve the logical to physical default rules and to manage the duplicate names in the data model.

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:

Figure 1-1-32: Name Mapping Tab-Model Naming Options

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:

Page 17: Using ERwin Data Modeler

Figure 1-1-33: Duplicate Names Tab-Model Naming Options

8. Click OK to apply the naming standards to the data model.

Forward and Reverse Engineering

You can use the technique of Forward engineering in ERwin to generate the physical schema based on a data model. It can be used to specify storage objects that must be generated for the data model such as the tables, triggers, and constraints. To Forward engineer a data model:

1. Open the Physical data model. 2. Select the menu options, Tools and Forward Engineer/Schema Generation to display

the Schema Generation window Options tab as shown in Figure 1-1-34:

Figure 1-1-34: Schema Generation–Option Tab

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:

Figure 1-1-35: Select Window

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.

Page 18: Using ERwin Data Modeler

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:

Figure 1-1-36: Reverse Engineering–Select Template Window

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.

To compare two models at the database level: 1. Open the current model that must be compared. 2. Select Tools > Complete Compare to open the Compete Compare wizard. 3. Select the Script File radio button in the Compare Current Model pane. 4. Click the Browse button to locate the file. 5. Choose the type of comparison to be performed from the available options:

Bidirectional, Update Current, or Update Other. 6. Click Next to select the items to be compared from the Items to Compare window, as

shown in Figure 1-1-37:

Figure 1-1-37: Complete Compare–Items to Compare

7. Click Next to show the Object Filter Option to specify the objects on the two models that must be compared.

Page 19: Using ERwin Data Modeler

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:

Figure 1-1-38: Complete Compare–Resolve Differences

9. Click OK to resolve the difference between the two models.

Point 2: Generating Database Design and Managing Large Models

AllFusion ERwin Data Modeler, from Computer Associates, is used to generate, enhance, and manage database designs. It enables you to visualize the structure, elements, and design for databases. AllFusion ERwin Data Modeler architecture not only combines the logical and physical model; it also supports the creation and maintenance of separate logical and physical models. AllFusion ERwin Data Modeler maintains the information pertaining to Entity Relationships (ER) in database models. It also supports the design and management of large database models by dividing them into smaller, manageable subject areas.

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.

Using Macros in AllFusion ERwin Data Modeler

Predefined macros in AllFusion ERwin Data Modeler are used in templates created for triggers, stored procedures, and preschema and postschema scripts. The only prerequisite for using these macros is that the database server must support them. These macros customize the built-in trigger templates by creating an override Referential Integrity (RI) template or by writing new Structured Query Language (SQL) triggers or stored procedures. Each predefined macro begins with the percent (%) symbol and can be used with different AllFusion ERwin Data Modeler objects, such as entities, tables, attributes, columns, relationships, and constraints.

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:

Page 20: Using ERwin Data Modeler

Table 1-2-1: Macro Scopes and Corresponding Template Types

Scope Trigger Templates Stored Procedures and Scripts

RI Override

Parent Insert, Update, Delete

Child Insert, Update, Delete

Stored procedures attached with tables and scripts using the %ForEachAtt and %ForEachEntity macros, respectively.

Trigger Override

Trigger Insert, Update, Delete Header

Trigger Insert, Update, Delete Footer

Custom Trigger Header, Footer or Default Body

Stored procedures attached with tables and scripts using the %ForEachAtt and %ForEachEntity macros, respectively.

Global All triggers, stored procedures, and scripts

� Return Value: The value returned from the database server after the macro is generated.

� Example: Includes the expanded code and sample template syntax for a specific macro.

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.

Macro Command Syntax

The syntax of a macro command consists of: � Keywords: Always begin with a percent (%) sign. For example, %AttFieldName. � Punctuation: Includes commas, braces ({ }), and parentheses (( )). Commas separate

multiple parameters, braces are used to specify results based on the keyword and the parameters, and parentheses specify parameters. To display an expanded code in a list, place the end brace on a new line in the template code.

� Parameters: Are displayed in angular brackets (< >). While typing the macro command in a trigger, stored procedure, or script, you can replace a parameter with text, numbers, SQL code, or other AllFusion ERwin Data Modeler macros.

For example, you use the %+ macro to add macro codes within the %+ macro. The syntax for the %+ macros is:

%+(<macro code1>,<macro code2>)

Where, macro_code1 and macro_code2 are added using the %+ macro.

The template code for the %+ macro is:

%+(5,9)

Where, 5 and 9 are passed as parameters to the %+ macro.

The expanded code for the %+ macro is:

14

The above expanded code is the result of the template code of the %+ macro.

Page 21: Using ERwin Data Modeler

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.

Inserting an AllFusion ERwin Data Modeler Macro in a Template

You can insert an AllFusion ERwin Data Modeler macro in a template for a trigger, stored procedure, or script. To insert an AllFusion ERwin Data Modeler macro:

1. Open the template in which the macro needs to be inserted. 2. Position the cursor in the template window to insert a macro.

Figure 1-2-1 shows the SQL Server Trigger Templates window:

Figure 1-2-1: The SQL Server Trigger Templates Window

3. Click the Macro Toolbox button to open the Macro Toolbox dialog box, as shown in Figure 1-2-2:

Figure 1-2-2: The Macro Toolbox Dialog Box

Page 22: Using ERwin Data Modeler

4. From the Macros list box, select the required macro. 5. Click Insert Macro and then click Close to close the Macro Toolbox window. 6. Specify the appropriate values, parameters, and variables for the inserted macro.

Customizing Triggers Using AllFusion ERwin Data Modeler

You can create triggers in AllFusion ERwin Data Modeler . Triggers are a named set of precompiled SQL statements stored on the database server and are automatically executed when a specific event occurs. For example, a trigger is fired when a row in a table is inserted, updated, or deleted. The trigger informs the DBMS how to process the SQL Insert, Update, or Delete commands to apply business rules.

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.

Including Macro Codes Across Trigger Templates and Multiple Files

You can use macro codes across different trigger templates and files. To implement this, the trigger template code or file should include the %Include macro in the beginning of the code. The syntax to use the %Include macro for files is:

%Include ("<file path name>")

The syntax to use the %Include macro for the trigger template is:

%Include (<trigger template name>)

The template code for the %Include macro is:

%Include ("c:\er\trg.txt")

%Include ("The template to include")

The expanded code for the %Include macro is:

The contents of the file or other templates are expanded.

Enforcing Relationships and RI Using Macros

You can enforce relationships and RI amongst the objects of AllFusion ERwin Data Modeler model using the %TriggerRelRI macro. This macro returns a True response when the trigger and the relationship are of the specified action, RI type, and integrity rule. The different trigger actions are Insert, Update, and Delete.

The integrity rules are: � Cascade: When an instance in the parent table is deleted, inserted, or updated, each

related instance in the child table is also deleted, inserted, or updated. � Restrict: Prevents an instance in the parent or child table from being deleted, inserted,

or updated if there are one or more related instances in the child or parent table.

Page 23: Using ERwin Data Modeler

� Set null: Sets the foreign key attributes or columns in each related instance of the child table to Null when an instance in the parent table is deleted, inserted, or updated.

� Set default: Sets the foreign key attributes or columns in each related instance of the child table to the specified default value when an instance in the parent table is deleted, inserted, or updated.

� None: Disables the trigger action of a trigger if the trigger action does not need to be generated.

The syntax to use the %TriggerRelRI macro is:

%TriggerRelRI (<action>, <RI type>, <integrity>)

The above syntax includes three parameters, the trigger action, RI type, and integrity rule.

The scope to use the %TriggerRelRI macro is:

RI or Rel Override, %If

The template code for the %TriggerRelRI macro is:

%If(%TriggerRelRI(Child, UPDATE, CASCADE)){%VerbPhrase Child UPDATE

CASCADE}

The expanded code for %TriggerRelRI macro is:

Is rented under CHILD UPDATE CASCADE

In the above expanded code, Is rented under is the phrase generated by the server through %VerbPhrase.

Default Trigger Templates Generated Using Macros

AllFusion ERwin Data Modeler provides a set of default trigger templates to generate SQL code. If you use these trigger templates, you do not need to type SQL code manually on the server. If the target DBMS server supports triggers, AllFusion ERwin Data Modeler includes default trigger templates that implement RI based on the relationships and options selected in AllFusion ERwin Data Modeler model. The various examples of the default trigger templates in AllFusion ERwin Data Modeler are: � Table roles in the relationship are Parent or Child. � SQL command types are Insert, Update, and Delete. � RI actions are Cascade, Restrict, Set Null, and Set Default.

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:

Listing 1-2-1: Template Code for the INSERT Trigger

Page 24: Using ERwin Data Modeler

create trigger %TriggerName on %TableName

for %Actions(",")

as

/* ERwin Builtin %Datetime */

/* %Actions(",") trigger on %TableName */

/* default body for %TriggerName */

begin

declare @numrows int,

@nullcnt int,

@validcnt int,

%PKDecl(,@ins)%decl(bComma,0)%ForEachAtt() {%if(%AttIsPk)

{%=(bComma,1)} }%if (%==(%:bComma,1)) {,}

@errno int,

@errmsg varchar(255)

select @numrows = @@rowcount

%ForEachChildRel() {

%RelTemplate

}

%ForEachParentRel() {

%RelTemplate

}

return

error:

raiserror @errno @errmsg

rollback transaction

end

go

Listing 1-2-2 shows the expanded code to insert a table:

Listing 1-2-2: Expanded Code to Insert a Table

Page 25: Using ERwin Data Modeler

create trigger Insert on Movie_Details

for INSERT

as

/* INSERT trigger on Movie_Details */

/* default body for Insert */

begin

declare @numrows int,

@nullcnt int,

@validcnt int,

@insMovie_ID varchar(20),

@errno int,

@errmsg varchar(255)

select @numrows = @@rowcount

return

error:

raiserror @errno @errmsg

rollback transaction

end

go

The above listing shows the expanded code of an Insert trigger added to the Movie_Detail table.

RI Trigger Templates in AllFusion ERwin Data Modeler

Business rules are logical constructs that express how a company uses data. AllFusion ERwin Data Modeler supports a set of built-in RI options to capture common business rules that apply to relationships between data available in different tables. RI rules can be enforced using the following programming techniques: � Application logic, such as front-end applications or stored procedures. � Declarative RI, that involves declaring which RI rule to enforce for each table

relationship in the schema using the RI default tab in the model properties. � Triggers, which are parts of SQL code and are automatically executed by the database

when a SQL Insert, Update, or Delete command is executed against a table.

Page 26: Using ERwin Data Modeler

You can use triggers to enforce RI rules on a database. Any changes in the business rule are implemented once because the triggers are centrally located in the database application. Triggers also support the enforcement of additional rules along with the default RI rules.

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.

Specifying Default RI Rules

AllFusion ERwin Data Modeler applies default RI rules and triggers to each relationship in the physical model. The methods to specify which default trigger AllFusion ERwin Data Modeler applies to a relationship are: � For all relationships in a model: Specifies the model properties to set the default RI

action. These settings are associated with each type of relationship in a model. � For an individual relationship: Specifies a different RI action for an individual

relationship in a model.

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:

Page 27: Using ERwin Data Modeler

Figure 1-2-3: The Model Properties Dialog Box

2. Click the RI Defaults tab. 3. Select a new action from the drop-down menus to modify an RI action for one or more

SQL action and relationship. 4. You can also click the Reset button to return the settings to the system default or click

the Rebind button to apply the new default settings to any existing relationship in the model.

5. Click OK.

Overriding Trigger Templates

You can use AllFusion ERwin Data Modeler to customize a template and change the trigger code that is generated by a built-in template. It also specifies that the customized version should override the built-in template. You can use the following templates to override the default trigger template: � RI Type Override Template: Creates a custom override template for each RI rule

combination. This custom template is used instead of the default template for all the relationships in a model that have been assigned to RI rule. When the templates are used to create a model, changes in the global RI trigger can be made at only one place and used in the model globally. If you select the RI Type Override check box for triggers, the RI Type Override Templates are used instead of AllFusion ERwin Data Modeler default templates.

� Relationship Override Template: Overrides the default template for a specific relationship. The built-in templates are changed and attached to the specific relationship.

� Table Override Template: Creates a custom table override trigger in a model. If you select the Table Override check box for trigger when generating the schema, the Table Override Templates are used instead of the built-in templates.

Creating RI Override Templates

You can use an RI Type Override template to change the behavior of the RI trigger . When you create an RI Type Override template, it is easy to generate custom RI triggers because the overridden RI trigger type automatically uses the template to which all the relationships are assigned. To create an RI Type Override template:

1. In the physical model, click Database -> RI Triggers -> Global Trigger Templates. The SQL Server Trigger Templates dialog box appears, as shown in Figure 1-2-4:

Figure 1-2-4: The SQL Server Trigger Templates Dialog Box

Page 28: Using ERwin Data Modeler

2. Select the template in the Built-in Trigger Template or User Override list to create a new template from the existing template, type a name for the new template in the Template Name textbox, and click Add to create a new template.

3. Type the text in the Template code box to add the code for the template or add AllFusion ERwin Data Modeler macro code by inserting a macro in the template.

4. In the Referential Integrity Type list, select the RI action to which the new template needs to be attached.

5. Click Attach above the User Override list. 6. Click Close.

Modifying RI Override Trigger Templates

An RI Override trigger template can be modified through the trigger template dialog box. To modify an RI Override trigger template:

1. In the physical model, click Database -> RI Triggers -> Global Trigger Templates. The SQL Server Trigger Templates dialog box opens.

Figure 1-2-5 shows the RI Override trigger template to be modified in the SQL Server Trigger Templates dialog box:

Figure 1-2-5: RI Override Trigger Template to be Modified

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.

Deleting an RI Override Trigger Template

You can delete an RI trigger template if you do not need to use it in the model. To delete an RI trigger template:

1. In the physical model, click Database -> RI Triggers -> Global Trigger Templates to open the SQL Server Trigger Templates dialog box.

2. From the User Override list, select the RI override trigger template to delete. 3. Click Delete, and then click Close.

Note

You can delete only the override trigger templates and not the built-in templates in AllFusion ERwin Data Modeler .

Overriding a Default Trigger Template

Listing 1-2-3 shows the override template code for the Child Delete Cascade trigger for the SQL Server:

Listing 1-2-3: Overriding a Default Trigger Template

Page 29: Using ERwin Data Modeler

/* ERwin Built-in %Datetime */

/* %Parent %VerbPhrase %Child ON Child Delete CASCADE */

update %Parent

set status = 'Deleted from %child'

from %Parent, deleted,%Child

where

/* %%JoinPKPK (%Parent, deleted) */

%JoinPKPK (%Parent, deleted) and

/* %%JoinFKPK (%Child, deleted) */

%JoinFKPK (%Child, deleted)

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

create trigger DelTrg on Movie_Copy

for DELETE

as

/* ERwin Builtin Wed Oct 23 19:58:50 2002 */

/* DELETE trigger on Movie_Copy */

/* default body for DelTrg */

begin

declare @numrows int,

@nullcnt int,

@validcnt int,

Page 30: Using ERwin Data Modeler

@insMovie_ID CHAR(18),

@errno int,

@errmsg varchar(255)

select @numrows = @@rowcount

/* ERwin Builtin Wed Oct 23 19:58:50 2002 */

/* Movie R/3 Movie_Copy ON CHILD DELETE CASCADE */

update Movie

set status = 'Deleted Movie_Copy'

from Movie, deleted,movie_copy

where

/* Movie.Movie_ID = deleted.Movie_ID */

Movie.Movie_ID = deleted.Movie_ID and

/* Movie_Copy.Movie_ID = deleted.Movie_ID */

Movie_Copy.Movie_ID = deleted.Movie_ID

return

error:

raiserror @errno @errmsg

rollback transaction

end

go

The above code shows the expanded code for the Child Delete Cascade trigger for the Movie_Copy table.

Customizing Stored Procedures Using AllFusion ERwin Data Modeler

A stored procedure is a set of precompiled SQL statements stored on a database server and invoked by the client using a remote procedure call. In AllFusion ERwin Data Modeler , you can add a stored procedure for tables and views at the model level. In addition, you can write the code for a stored procedure in AllFusion ERwin Data Modeler.

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.

Page 31: Using ERwin Data Modeler

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.

Adding a Stored Procedure Using Model Explorer

You can add stored procedures to AllFusion ERwin Data Modeler using the Model Explorer window. To add a stored procedure using Model Explorer:

1. In the Model Explorer window of a physical model, expand the Stored Procedures node and then right-click either Model Level Procedures or Table Level Procedures.

Figure 1-2-6 shows the Model Explorer window.

Figure 1-2-6: The Model Explorer Window

2. From the shortcut menu, click New. 3. In the edit box, type a name for the stored procedure. 4. Press Enter. The Model Explorer window displays stored procedures in the order in

which they are added.

Attaching a Stored Procedure to a Table or a View

You can attach table-level stored procedures in the physical model to a table or a view. To attach a stored procedure to a table or view:

1. In the Model Explorer window of the physical model, open the Table Level Procedures hierarchy from the Stored Procedures hierarchy.

2. Right-click the stored procedure name to attach to the Table Level Procedure hierarchy. This opens the Stored Procedures window, as shown in Figure 1-2-7:

Figure 1-2-7: The Stored Procedures Window

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:

Page 32: Using ERwin Data Modeler

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.

Detaching a Stored Procedure from a Table or a View

You can detach a stored procedure attached to a table or view if you do not require it in the model. To detach a stored procedure from a table or view:

1. In the Model Explorer window of the physical model, select the procedure to be detached from a table or view.

2. Right-click the stored procedure to open the Stored Procedures window. 3. Click the Browse button to open the Stored Procedure Browser dialog box, as shown

in Figure 1-2-9:

Figure 1-2-9: The Stored Procedure Browser Dialog Box

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.

Changing the Code for Stored Procedures

You can use AllFusion ERwin Data Modeler to change the code for stored procedures. To change the code for stored procedures:

1. In the physical model, click Database -> Stored Procedures. 2. Select Table-Level to change the code for a table-level stored procedure or select

Model-Level to change the code for a model-level stored procedure. Figure 1-2-10 shows the Code tab in the Stored Procedures dialog box:

Figure 1-2-10: The Code Tab in the Stored Procedures Dialog Box

Page 33: Using ERwin Data Modeler

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.

Deleting a Stored Procedure

You can delete a stored procedure template that you do not require in the model or in the table. To delete a stored procedure from a model, table, or view:

1. In the physical model, click Database -> Stored Procedures. 2. Select Table-Level to delete table-level stored procedures or select Model-Level to

delete model-level stored procedures. Figure 1-2-11 shows the Delete button in the Stored Procedures dialog box, which is used to delete the selected stored procedure:

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.

Changing the Order of Stored Procedure Generation

You can change the order in which the stored procedures are added to a model, if necessary. To change the order of generating a stored procedure:

1. In the physical model, click Database -> Stored Procedure. 2. Select Model-Level to open the model-level Stored Procedure dialog box. Figure 1-2-

12 shows the Stored Procedures dialog box with the selected stored procedure. The dialog box provides up and down buttons to change the order of generating the stored procedure.

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.

Migrating a Stored Procedure

AllFusion ERwin Data Modeler macros are used to write stored procedures that are independent of the physical data constructs. Different database servers support various SQL

Page 34: Using ERwin Data Modeler

statements and syntax. This means that the template created for a Sybase database is different from the one created for Informix . When a stored procedure is migrated from one target database server to another, you need to change the SQL code for the stored procedure to accommodate server-specific SQL constructs.

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.

Point 3: Generating Reports Using ERWin Data Modeler

The report-generating feature of ERWin enables you to create and manage reports about the physical and logical models of the ERWin data modeler. The physical model represents the physical objects of the database model and the logical model represents the business rules of the database model. ERWin provides two tools, the Report Template Builder and the ERWin Data Browser, to generate reports. The Report Template Builder enables you to create report templates of objects included in the ERWin model. The ERWin Data Browser provides categories, such as table name and attributes, to generate reports. The reports display a list of objects, the attributes of the objects, the relationships among the objects, and the data types of attributes.

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.

Report Template Builder

The Report Template Builder is an ERWin data modeler tool that includes some standard report templates. It also enables you to create and generate templates of objects contained in an ERWin model. You can reuse these report templates to create reports of similar types. Reports in ERWin can be in various formats, such as HTML, text, or Rich Text Format (RTF).

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.

Figure 1-3-1 shows the Toy Universe model:

Page 35: Using ERwin Data Modeler

Figure 1-3-1: The Toy Universe Model

Describing Standard ERWin Reports

The ERWin Report Template Builder consists of standard report templates to generate reports about ERWin models. The report templates that enable you to generate reports in the HTML format are: � HTML Entity Primary Key.rtb: Creates a tabular report in HTML format, which lists the

table and the corresponding primary keys in the model. � HTML Physical Only Columns.rtb: Creates a hierarchical report in HTML format, which

lists the columns of the physical model. � HTML Table Owner.rtb: Creates a tabular report in HTML format, which lists the tables

and owners of the model.

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:

Page 36: Using ERwin Data Modeler

Figure 1-3-2: The Report Templates Dialog Box

Creating the Standard Template

You can create a standard template with the desired format using the Report Template Builder tool. You may then use the standard template to create various other reports. To create a standard report template:

1. Open the Report Templates dialog box. 2. Click New. The Report Template Builder window appears, as shown in Figure 1-3-3:

Figure 1-3-3: The Report Template Builder Window

3. Double-click Document Untitled in the Report Layout frame. The Properties window appears.

Figure 1-3-4 shows the Properties window for Document Untitled:

Figure 1-3-4: The Properties Window for Document Untitled

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.

Figure 1-3-5 shows the Title tab in the Properties window:

Figure 1-3-5: The Title Tab in the Properties Window

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.

Page 37: Using ERwin Data Modeler

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.

Figure 1-3-7 shows the Properties window of the Table object:

Figure 1-3-7: The Properties Window of the Table Object

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:

Figure 1-3-8: The Report Template Builder Preferences Window

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.

Running a Report Template

You need to run the report template to view the created report template. Running the report template makes the values of each column added to the report template visible. To run a report template in Report Template Builder:

1. Open the Report Template Builder window. 2. Click File-> Open to open the desired report template.

Figure 1-3-9 shows the Report Template Builder window with a standard template created:

Figure 1-3-9: A Report Template in Report Template Builder

Page 38: Using ERwin Data Modeler

3. Click File-> Run.

Figure 1-3-10 shows the output of the report template after running it on a Web browser:

Figure 1-3-10: The Output of the Report Template 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-11 shows a report of the Toy Universe model:

Figure 1-3-11: A Report of the Toy Universe Model

Editing a Report Template

To edit a report template means to make changes to the template of an existing report. You can edit an ERWin report template by adding or deleting sections in the report or by changing the format of existing sections in the report. To edit a template:

1. Open the Report Templates dialog box. 2. Select a report template from the Available Templates list box.

Figure 1-3-12 shows the Report Templates dialog box with a template selected for editing:

Figure 1-3-12: The Report Templates Dialog Box

3. Click Edit to open the selected report template for editing.

Managing Report Results

A report file is generated each time a report is run and saved in the directory where the report is stored. The report is shown in the format selected to design the report. For example, while creating the report template, if you select the HTML format option in the Report Template Properties dialog box, the report is opened on a Web browser.

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

Page 39: Using ERwin Data Modeler

Report Format Generated Report File(s)

RTF <report name>.rtf

HTML <report contents>.html

<report graphics>.jpeg

TEXT <report name>.txt

<report name>.csv

Creating a Picture Report

ERWin reports can also contain pictures by including the Picture section in the report template. The pictures can include the database model diagram for which the report is generated. To insert a Picture section in a report template:

1. Open Report Template Builder. 2. Open the report template in which you need to insert the Picture section. 3. Select Picture under the Graphical node in Report Template Builder and add to the

Report Layout frame.

Figure 1-3-13 shows Report Template Builder with the Picture section:

Figure 1-3-13: 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.

Figure 1-3-14 shows a sample picture report on the Web browser:

Figure 1-3-14: A Sample Picture Report on the Web Browser

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.

Figure 1-3-15 shows the Browse for Folder dialog box:

Page 40: Using ERwin Data Modeler

Figure 1-3-15: The Browse for Folder Dialog Box

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

4. Select a report name from the Available Templates list box. 5. Click Edit. The Import From ERP dialog box appears, as shown in Figure 1-3-17:

Figure 1-3-17: The Import From ERP Dialog Box

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.

Creating Reports Using Data Browser

Page 41: Using ERwin Data Modeler

The Data Browser enables you to create and generate reports for the current state of the model in addition to the changes made to the model. To create ERWin reports using the Data Browser:

1. Open the ERWin Data Modeler application. 2. Click Tools-> Data Browser. The Data Browser window opens, as shown in Figure 1-3-

18:

Figure 1-3-18: The Data Browser Window

3. Click File-> New ERWin Report. The Reports dialog box appears, as shown in Figure 1-3-19:

Figure 1-3-19: The Reports Dialog Box

4. Type the report name in the Name text box. 5. Select the Logical option if you need to generate a report about the logical model or

select the Physical option to generate a report about the physical model. 6. Select a category from the Category drop-down list box to generate a report based on

the selected category. 7. Select options from the Options tab to show relevant details in the report. 8. Click OK to add the report to Data Browser. 9. Select the report added to Data Browser. 10. Click File-> Execute Report to run the report for the current model. Alternatively, you

can click the Execute button from the toolbar.

Figure 1-3-20 shows Data Browser with the generated report:

Figure 1-3-20: Data Browser with the Generated Report

Editing Reports Using Data Browser

Using the Data Browser, you can edit the format of a report, change column headings, or select the columns to be added to the result set. For example, you may need to edit the ToyUniverse report to remove the Table Column Name. To edit the ToyUniverse report in Data Browser:

1. Open the Data Browser window. 2. Select the ToyUniverse report from the Reports tree.

Page 42: Using ERwin Data Modeler

3. Click Edit-> Report Format. The Report Format dialog box appears. Alternatively, you can right-click the selected report and select the Edit Report option from the pop-up menu or click the Edit Properties button from the toolbar.

Figure 1-3-21 shows the Report Format dialog box:

Figure 1-3-21: The Report Format Dialog Box

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.

Figure 1-3-22 shows the edited ToyUniverse report:

Figure 1-3-22: The Edited Report

Searching Items in the Result Set

Data Browser enables you to search a specific component in a report. For example, you can search the Description attribute in the Toys table of the ToyUniverse report using Data Browser. To do this:

1. Open the Data Browser window. 2. Select the ToyUniverse report from the Reports tree. 3. Click View-> Find. The Find in Result Set dialog box appears, as shown in Figure 1-3-

23:

Figure 1-3-23: The Find in Result Set 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.

Figure 1-3-24 shows the output of the searched item:

Page 43: Using ERwin Data Modeler

Figure 1-3-24: The Output of the Searched Item

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:

Figure 1-3-25: The Export from Data Browser Dialog Box

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.

Figure 1-3-26 shows the ToyUniverse report on the Web browser:

Figure 1-3-26: The ToyUniverse Report on the Web Browser

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:

Page 44: Using ERwin Data Modeler

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.

Enabling the Data Movement Rule Feature

The Data Movement Rule feature is not enabled by default. To use this feature, you need to set the related option in the Model Properties dialog box. To add the Data Movement Rule feature:

1. Click Model-> Model Properties in the physical model window. The Model Properties dialog box appears, as shown in Figure 1-3-28:

Figure 1-3-28: The Model Properties Dialog Box

2. Select the Data Movement check box in the General tabbed page. 3. Click OK to close the Model Properties dialog box.

Creating a Data Movement Rule

Page 45: Using ERwin Data Modeler

The Data Movement Rule option enables you to create and attach rules to the tables in the ERWin model. To create a Data Movement Rule:

1. Open the ERWin Data Modeler application. 2. Click Model-> Data Movement Rules. The Data Movement Rules dialog box appears,

as shown in Figure 1-3-29:

Figure 1-3-29: The Data Movement Rules 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.

Attaching Rules to Tables

After creating rules, you need to attach them to tables to implement the rules. To attach a rule to tables included in the model:

1. Open the Data Movement Rules dialog box. 2. Select the Attachment tab.

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.

Deleting a Data Movement Rule

When database model has a rule that it does not need, you must delete it. To delete a rule from the Data Movement Rules dialog box:

1. Open the Data Movement Rules dialog box.

Figure 1-3-31 shows the Data Movement Rules dialog box with the Delete button:

Page 46: Using ERwin Data Modeler

Figure 1-3-31: The Delete Button in the Data Movement Rules Dialog Box

2. Select the rule you want to delete. 3. Click Delete to delete the selected rule. 4. Click OK to close the Data Movement Rules dialog box.