Chap05 - Building The Data Model
Chap05 - Building The Data Model
We find that all business processes either consume or produce data. In order to use the data effectively there must be robust, consistent representation of the data and their relationships to each other. Entity Relationship Diagram is a tool within the Oracle Designer repository that enables you to model the data needed by your business processes. It visually represents the information requirements of a system. n ERD is a communication tool that the designer uses to reach agreements with the users about their business requirements. !y identifying and describing the data and the relationship among them, the designer can use the tool to effectively base the design of the underlying database. "urther, the ER model is independent of any data storage or access method. "or e#ample, the following diagram represents a relationship between two entities, Order and $ustomer. We state that a $ustomer may place %ero or more Orders while an Order must be for a $ustomer. &ame is shown as a required attribute of the $ustomer whereas 'hone is optional. s we see here, the diagram not only tells us about the business information but also how that information may be related.
Entity
Relationship
Attributes
ORDER
for places
Figure 1Example of an Entity Relationship Diagram Data modeling involves the following stages, which can be performed iteratively until you are satisfied with the description of your data( Identifying entities Establishing relationships Entering attributes Defining domains Establishing unique identifiers 'erforming quality chec)s *he entity relationship diagram that results from the above operations can be translated into a relational database design during the design stage of your systems development. *he Database Design *ransformer, accessed from the Entity Relationship Diagrammer +ERD,, creates table mappings and detailed mappings to automate the mapping of your analysis definitions. We shall see this in a later chapter. In this chapter we e#amine the ERD tool and build the ER model for the $D $ollections. !ut, first we shall e#plore the terminology.
Components of ERD
n entity relationship diagram is made up of entities and their relationships. In addition we define meta information such as domains, attributes, and business rules.
11
Entity
n entity is a thing of significance, whether real or imagined, about which we need information to be held or )nown. "rom an ob-ect oriented point of view an entity is a class, a group of things. specific instance is not an entity. it will be an ob-ect, a record. *ypical e#amples of entity would be Order, ssignment, /tudent, $D, etc. Each entity must have a unique, meaningful name. It is also desirable to provide a short name for easy identification. If you do not specify the short name the ERD will generate one by abbreviating the entity name. &ote that this may sometimes result in unsavory names0 Do not provide a plural name unless you want to override the ERD supplied name. well designed data model should have, for each entity, the complete details of( alternative names for the entity, namely, synonyms the initial number of occurrences of this entity the ma#imum number of occurrences of this entity the average number of occurrences of this entity the growth rate
*he above features are defined by editing the properties of the entity. *hese rules are imperative for professional data modeling. *o edit properties, select the ob-ect +entity, and chose Edit properties.
1!
Attribute
ttributes are details, descriptions, or properties that qualify, identify, classify, quantify, or e#press the state of an entity, and can be defined for e#isting entities only. *his information is often termed meta data by database vendors. ttributes are the lowest level of data definition included in the data model, and they need a lot of detail about them, such as name, type, length, and default values. $omprehensive information is important for later tas)s in the development of your system. Each attribute in an entity must have a unique name. *he optionality of the attribute should also be specified. It is recommended that each entity has at least two attributes. *o ma)e sure that the data model is complete, you should e#amine each entity to ma)e sure that you have all the attributes, and ensure that, for each attribute, you specify( details of any domain that you could use the correct optionality for optional attributes, the number of occurrences that have values, initially and on average both ma#imum and average length a default +initial, value, if none is provided on creation +important for mandatory attributes, allowable values
*he types of the attributes that are displayed on an entity are indicated by the symbol displayed to the left of the attribute name. /ymbol 1 4 o Description 2nique Identifier +2ID, combination of attributes and3or relationships that serves to identify uniquely an occurrence of an entity. 5andatory ttribute Optional ttribute
*he Database Design *ransformer uses attributes as the basis for column definitions in creating a default database design from an ER model. *he /erver 6enerator then uses these definitions to create the actual columns in the physical database.
1"
Domain
domain is a set of business validation rules, format constraints, and other properties that apply to a group of attributes. ttributes and columns in the same domain are sub-ect to a common set of validation chec)s. 2seful domains are those things that never or rarely change, such as days of the wee), currency values and yes3no values. Domains help you define similar attributes consistently and quic)ly. Domains can be defined before entities and attributes are created. *o ma)e sure that the data model is complete, you should ensure that, for each domain, you specify( domain name format datatype length valid values what would be a null value representation default initial value
When a domain has been created, values of attributes can be specified quic)ly by selecting from the domain. domain can also be used as a 7short8cut7 when creating column definitions in the database design. *he Designer39::: 6enerators use domain values when generating applications. ;ou may find it useful, at the same time as you are drawing a diagram in the Entity Relationship Diagrammer, to have a Repository Ob-ect &avigator window open, showing the 'roperties Window for domains.
1#
U$D
unique identifier is a combination of attributes and3or relationships that uniquely identifies an occurrence of an entity. One of the unique identifiers for each entity must be specified as that entity<s primary )ey. unique identifier may be made up of one or more attributes, one or more relationships, or a combination of attributes and relationships. One entity can have several unique identifiers but only one can be a primary unique identifier. It is advisable to )eep the primary unique identifier short +not the name but the list of attributes that form this, because this will be used frequently when developing your system. *he Database Design Wi%ard uses each primary unique identifier to create the primary )ey for the table definition.
1.4.1
Relationship
Relationships are named significant associations between two entities, and can be established for e#isting entities only. *hough many types of relationships e#ist, ma-orities of these are one to many. *he optionality and the degree of each relationship end need to be identified. Each end of the relationship must also be named. recursive relationship is one in which an entity is related to itself. We use arcs to indicate mutual e#clusivity of relationships +advanced topic,. relationship model is complete when for each relationship end you have specified whether it is transferable a logical name
the ma#imum, minimum and average number of occurrences of the entity that is involved for =many> relationship ends, what the ma#imum and minimum occurrences of the entity in any one relationship are
2 !1
;ou can launch the ER diagrammer either from the launch pad or from the Repository Ob-ect &avigator. *o wor) with an e#isting diagram, clic) on the open folder icon and choose a diagram from the pull down list. ;ou may also "ile Open and select the diagram. *o create a new diagram either select "ile &ew or clic) on the new document icon. n empty diagram window opens up. ;ou can either enter all the entities at once or then draw the relationships among these or you may wor) on groups of entities, establishing the relationships as you progress. $lic) on the ma#imi%e button to e#pand the window to fill the available screen real estate.
2.1.1
?. 9. @.
Creating entities
In the Entity Relationship Diagrammer, clic) 5ove the mouse pointer to the area of the diagram in which you want to position your entity. *o create the new entity at the default si%e, clic) the mouse button. *o create the new entity larger or smaller than the default si%e, drag the entity bo# to the desired si%e for the entity, and release the mouse button. positioning the entity bo# in the appropriate position can create /ub8types and super8types. *o create a super8type, position and stretch the entity bo# over and around the entity or entities that will become its sub8types, and release the mouse button. *o create a sub8type, position the entity bo# inside the entity that will become its super8type, and release the mouse button. Enter the name of the entity. Enter a short name for the entity, then clic) OC. If you do not enter a short name the tool will choose a default short name that is merely a shortened version of the full name. *herefore, you may want to specify your own short names to avoid the ris) of any duplicate short names. lso, ma)e sure the short names are not any Oracle system words +e.g., $O&,.
*o create an entity(
&ote(
A. B. &ote(
Figure 2 Create Entity Dialog *he use case for the $D $ollections reveal five entities, namely, 5ar)eting 5aterial, $D, Dendor, Order, and $ustomer. We decide to create all five entities on our canvas because we )now what these are. Eaving all entities on the canvas allows us to position them as we li)e.
common error that users ma)e in creating ERDs is to use the canvas to conceptuali%e the entities. It never wor)s. ;ou should have already defined your entities and decided what attributes these entities would possess. ;ou should also have clearly defined the relationship between the entities.
Figure 3 The Five Entities t this point we have not defined the attributes nor drawn the relationships. Eaving these five entities on the canvas, however, help us visuali%e the relationship a little better.
$reating a fully attributed data model requires that you define all the significant attributes of the entities. /ince many of the attributes may share similar characteristics, it is easier if you define the domains for these attributes. s e#plained earlier, a domain eases design woes and builds consistent data design. Once again this is a step that can not be done on the fly at the machine. "orethought and discussion is warranted to produce stable domains. Identify all possible domains. Domains could be defined to set even trivial features such as format, length, etc. "or e#ample, all name or description fields may be set to be variable length character fields of certain ma#imum length.
3.1.1
?. 9. @.
Creating domains
In the Entity Relationship Diagrammer, choose Edit Domains. /elect the Definition tab to display the mandatory and most frequently used details of a domain. Insert a new attribute row by doing one of the following( to insert a new attribute in the current row, clic) on an empty attribute row. to insert a new attribute row before the currently selected row, clic) on the Insert Row button.
*o create a domain(
@.
*o enter detailed information about the domain, such as the format details for the attributes in a domain, or the valid units of measurement, select the Detail tab and enter the required details.
A.
*o enter information about the allowable values for elements in a domain, select the Dalues tab and enter the required details. Ranges of values, lists of values or code conversions may also be entered in this tab. *o enter free format multi8line te#t for the te#t types associated with the domain, select the *e#t tab and enter the required te#t. *o create the domain, clic) OC.
B. F.
/pecify same length. *e#t format will ignore any length data.
$hec) if a table of values are to be created in Oracle Figure 4 Entering Domain Details @.?.?.? Domain Dalues *his tabbed window is used to define the domain values that attributes, columns, program data constructs, parameters or data structures can ta)e. *he information can be used for deriving validation modules. Range of values, lists of values or code conversions may be entered in this tab. *he sequence numbers are also used by the 6enerator to define the order of sequence of Radio 6roup buttons. *he values with their meanings will show up in a pop8up list on the application. &ote( Do not include the G character in the te#t of the domain value. *he G symbol is used by Oracle to mean a run time variable.
Figure 5 Defining the Values of a Domain In the following figure we show the Domain Definition tab window. Eere you see the E5 IH domain derived from the HO&6 /*RI&6 domain. /uch supertype dependencies can be set to reuse definitions that are already in place. 2nli)e $II or other ob-ect oriented languages, you can not use multiple inheritance. If you have allowable values defined for a supertype then these will become part of the allowable values you define for the subtype.
Figure
Domain Definition
3.1.2
?. 9. @. A. B. ?. 9. @.
Creating attributes
In the Entity Relationship Diagrammer, double8clic) on the entity for which you want to create attributes. /elect the ttributes tab to display the attribute definition details. Detailed attribute information and attribute values are defined on the tt Detail and tt Dalue tabs respectively. Insert a new attribute row by doing one of the following( to insert a new attribute in the current row, clic) on an empty attribute row. to insert a new attribute row before the currently selected row, clic) on the Insert Row button. Enter the appropriate details for the attribute. ;ou must enter at least a name and format. 2se the scroll bars to scroll to properties of the attribute which are not currently displayed. *o save the new attribute, clic) OC. In the Entity Relationship Diagrammer, select the entity whose attributes you want to delete and choose Edit 'roperties. ;ou can also double clic) the entity. /elect the ttribute tab to display the attribute definition details. Detailed attribute information and attribute values are defined on the tt Detail and tt Dalue tabs respectively. /elect the row for the attribute you want to delete, and clic) Delete Row.
*o create an attribute(
*o delete an attribute(
A. &ote(
*o save the changes, clic) OC. If the selected element is not consistent with the Repository you will be as)ed whether you want to requery that element. Only elements that are consistent with the Repository can be edited.
Figure ! Creating "ttri#utes If, after creating the attributes, you change the domain definitions you must update the attributes in domains. *o do this select 2tility 2pdate ttributes in Domains. $hoose selected domains or all to update. In the above e#ample, the 5ar)eting 5aterial entity does not have any mandatory attributes +Opt chec)bo# empty,. &or have we mar)ed any of the attributes as 'rimary. *his is because we e#pect the system to generate a primary )ey column with an automatic sequence number. We shall see how to do this in a later chapter.
3.1.3
2nique identifiers may consist of an attribute, a combination of attributes, a combination of relationships or a combination of attributes and relationships. ?. 9. @. A. B. *o create an initial primary unique identifier( /elect the ttributes tab of the Edit Entity dialog bo# or the Definition tab of the Edit Relationship dialog bo#. On the ttributes tab of the Edit Entity dialog bo#, chec) the bo# in the 'rimary column for each attribute that you want to be in the unique identifier. On the Definition tab of the Edit Relationship dialog bo#, you chec) the 'rimary 2ID chec)bo#. Rename the 'rimary 2ID by appending J'C to the name.
s in the illustration below, ORDJ'C is the unique primary )ey identifier for the ORDER entity. It is associated with the ORDER &25!ER attribute.
*he five entities are now fully described with all significant attributes. We have also ta)en care to define domains and use these wherever applicable. *he fully attributed entities are shown below. *he 1 to the left of the attribute name implies a primary )ey attribute. n 4 means the attribute is mandatory +no nulls allowed, and an o means the attribute is optional +nulls allowed,. *here are a few items to note. &ot all entities have a primary )ey identified. If and only if an entity has an attribute +or attributes, that naturally yields a primary unique identifier should you show that here. In our e#ample, only $D ID and ORDER &25!ER are natural primary )ey attributes. Other entities may require either artificial )ey attributes +called surrogates, or may be derived from relationships between entities. We will e#amine surrogate )eys later.
#1
?.
Creatin%&relationships
In the Entity Relationship Diagrammer, clic) the button for the type of relationship you want to create. 5(? +5andatory to Optional, Relationship button 5(? +Optional to Optional, Relationship button 5(? +Optional to 5andatory, Relationship button 5(? +5andatory to 5andatory, Relationship button 5(5 +Optional to Optional, Relationship button 5(5 +5andatory to Optional, Relationship button ?(? +5andatory to Optional, Relationship button ?(? +Optional to Optional, Relationship button ?(? +5andatory to 5andatory, Relationship button
*o create a relationship(
9. @.
$lic) on the entity you want to be at the first end of the relationship. $lic) on the entity you want to be at the other end of the relationship.
A.
&ote( *o insert a dog8leg in the relationship, clic) the mouse button in free space on the diagram where you want to create the dog8leg. *he Relationship &ames preference, set in the $ustomi%e dialog bo#, determines whether or not relationship names are displayed on the diagram. "or e#ample, to create a $D to DE&DOR relationship that is 5any8to8one +many $Ds from a Dendor, we select the +5(? K 5andatory to 5andatory, tool from the tool palette. /tart at $D and drag towards DE&DOR. When you release the mouse, the following dialog shows. *he "rom &ame corresponds to $D, as that is where we come from. *o &ame corresponds to DE&DOR as that is where we are going. We can now read the relationship as one or more $Ds are bought from a DE&DOR and a DE&DOR sells one or more $Ds.
Figure 1. Creating Relationship s seen in the "igure below, for the two relationship panels there are items that e#plain the optionality and degree of relationship. *he dotted line means %ero while the solid line means e#actly one. /imilarly, the crow>s foot means more than one. *hus in the e#ample below, we say, a 5 RCE*I&6 5 *ERI H instance must promote one and only one $D and a $D may have %ero or more 5 RCE*I&6 5 *ERI H instances. In plain English we say a $D has many different promotional material but any given promotional material can be for only one $D. *his does not mean several copies of the same promotional material can not e#ist0
4.1.1
2nique identifiers may consist of an attribute, a combination of attributes, a combination of relationships or a combination of attributes and relationships. *his procedure is primarily for creating alternate unique identifiers. *o create a unique identifier( ?. 9. &ote In the Entity Relationship Diagrammer, double8clic) on the entity for which you want to create a unique identifier. /elect the 2IDs tab to display the unique identifier details. 2ID will have been created if any of the attributes are mar)ed as 'rimary on the ttributes tab. *his 2ID will initially be given an automatically generated name, which you can change as described in the following step. $lic) on an e#isting unique identifier name or on an empty &ame cell. *o insert a new row before the currently selected row, clic) on the Insert 2ID button. "or each 2ID, say whether it is primary by chec)ing the bo# in the 'rimaryL $olumn. Include the required attributes and relationships in the 2ID by highlighting them in the relevant $andidate field and clic)ing on the DOW& RROW button. Remove any unwanted attributes and relationships in the 2ID by highlighting them in the 2nique Identifier $ontents field and clic)ing on the 2' RROW button. *o create the 2ID, clic) OC.
@. A. B. F. M.
&otice that in the above e#ample, the DE&DOR & 5E attribute, which is mandatory, may be used in the unique identifier DE&D 2I. We do not have any attribute defined for the primary 2ID, even though DE&D 'C is the 'rimary 2ID for the entity. *he Database Design *ransformer will create a primary )ey column for the table. It is inadvisable to create unique identifiers using optional attributes, as uniqueness cannot be ensured. *he following figure shows the fully attributed data model with all significant relationships between entities. &ote that the relationship between $D and ORDER is many8to8many. *hough it is acceptable to define ER models with many8to8many relationships, it is a good practice to resolve these types of relationships prior to Database Design *ransformation. Oracle does not use any symbols to represent the cardinality of the relationships, for e#ample, the bars or circles +o, that you see at the relationship ends in other tools. *he dotted line represents optionality. *he empty diamond on the relationship end implies that the relationship is not transferable. *hat is, an Order instance cannot be transferred to another $ustomer.
Figure 12'nresolve+ Fully "ttri#ute+ ER -o+el ;ou may also want to 7resolve7 each many8to8many relationship into two one8to8many relationships with a new intersection entity. lternatively you could leave them as many8to8many relationships and allow the Database Design *ransformer to create intersection tables. ttention can be drawn to specific entities or sections of a diagram by using different colors or fonts, and several diagrams can be created to cover the information model. "or e#ample, you could have one diagram showing all the entities, and additional diagrams for each area of data. *he layout of the whole diagram or of selected elements can be changed using the autolayout utility. Each time the autolayout utility is run, a different layout of elements is displayed. *he process can be repeated as many times, as you require.
/everal Repository reports are available for you to conduct quality chec)s of your data model. *hese include Entity Definition Entities and their ttributes ttribute Definition ttributes in a Domain Entity 5odel Reference Entity $ompleteness $hec)s *hese reports ensure the following. "or each entity( Does the name accurately describe the dataL re there any synonyms for this entityL Eow many occurrences are thereL What is the growth rateL re there any sub8typesL re there any other unique identifiers for this entityL Which unique identifier is the primary )eyL
"or each relationship( $an you read the relationship from one entity to the otherL Is the relationship transferableL re you really sure of the optionality of the relationship endL Eave you resolved many8to8many relationships wherever feasibleL
"or each attribute( Does it have a logical nameL Is there a domain that you can useL Is the attribute really optionalL "or the entity relationship diagram( Is it presentable, with legible elements and few crossing linesL $an you argue that the diagram reflects the business area accuratelyL $ould you use it to describe the data to a userL
"
&ote(
fter automatically laying out a diagram, the utility also minimi%es the number of pages that the diagram covers. *o improve the printed appearance of a diagram, you can move the elements on a diagram so that they cover the minimum number of pages. Increase the default entity height and width in the $ustomi%e dialog bo#. Reduce the si%e of the diagram, where possible. /elect all of the elements on the diagram before running the utoHayout utility again. *his gives the utility the ma#imum fle#ibility when rearranging elements on a diagram. Reposition all elements automatically on the active diagram( ?. 9. In the Entity Relationship Diagrammer, ensure that no elements are selected on the active diagram. $hoose Hayout utoHayout. In the Entity Relationship Diagrammer, select the elements to be automatically laid out. $hoose Hayout utoHayout.
*here are four ways in which elements can be automatically laid out on a diagram. I.
II.
Reposition selected elements automatically on the active diagram +one in the front,( ?. 9.
III.
Reposition selected elements automatically within a new defined autolayout area on the active diagram( ?. 9. @. A. In the Entity Relationship Diagrammer, select the elements to be automatically laid out. $hoose Hayout utoHayout to &ew rea. 'osition the mouse pointer at the point on the active diagram at which you want to start defining the autolayout area and hold the mouse button down. Drag the rubber8band bo# to the si%e required for the autolayout area and release the mouse button.
&ote( ID.
better autolayout result can be achieved if the autolayout area you select contains a large amount of free space. Reposition selected elements automatically within a previously defined autolayout area on the active diagram( ?. 9. /elect the elements to be automatically laid out. $hoose Hayout utoHayout to /ame rea.
*he selected elements are automatically laid out within the previously defined autolayout area.