Скачать презентацию Chapter 7 Data Modeling Using the Entity Relationship Скачать презентацию Chapter 7 Data Modeling Using the Entity Relationship

eed9f9164f5899e667e53d9a378cac21.ppt

  • Количество слайдов: 48

Chapter 7 Data Modeling Using the Entity. Relationship Model p High-level conceptual model Used Chapter 7 Data Modeling Using the Entity. Relationship Model p High-level conceptual model Used for the conceptual design of DB applications Many DB design tools employs its concepts p Chen 1976 -- MIT p p n “The Entity Relationshipodel -- Toward a Unified View of Data” ACM - TODS 1

p 43 2 p 43 2

Overview of Database Design Process p Two main activities: n n p Focus in Overview of Database Design Process p Two main activities: n n p Focus in this chapter on database design n p Database design Applications design To design the conceptual schema for a database application Applications design focuses on the programs and interfaces that access the database n Generally considered part of software engineering 3

Entities, Attributes p Entity - a ”thing” in the real world with independent existence Entities, Attributes p Entity - a ”thing” in the real world with independent existence Attribute - properties that describe the entity n Simple (atomic) vs. composite n Single-values vs. multivalued n Stored vs. derived n Null values n Complex Attributes {Address. Phone({Phone(areacode, phonenumber)}, Address(Street. Address(Number, Street, Apt. Number), City, State, Zip))} p 4

5 5

6 6

Entity Types, Entity Set, Keys, and Value Sets p Entity Types: Defines a collection Entity Types, Entity Set, Keys, and Value Sets p Entity Types: Defines a collection (or set) of entities that have the same attributes e. g. employee, student p Entity Set: The collections of all entities of a particular entity type e. g. employee = set of all employees p Value Sets: specifies the set of values assigned to attribute (domain of values) 7

8 8

9 9

10 10

11 11

12 12

Dependencies p 1) Existence Dependency n n X and Y are entities Y entity Dependencies p 1) Existence Dependency n n X and Y are entities Y entity cannot exist without X entity Y cannot enter the database unless its corresponding X is there p if X is dropped from the database, Y must be dropped as well p n n X = strong, parent, owner, dominant Y = weak, child, dependent, subordinate 13

Weak Entity Types An entity that does not have a key attribute p A Weak Entity Types An entity that does not have a key attribute p A weak entity must participate in an identifying relationship type with an owner or identifying entity type p Entities are identified by the combination of: p n n p A partial key of the weak entity type The particular entity they are related to in the identifying entity type Example: n n n A DEPENDENT entity is identified by the dependent’s first name, and the specific EMPLOYEE with whom the dependent is related Name of DEPENDENT is the partial key DEPENDENT is a weak entity type EMPLOYEE is its identifying entity type via the identifying relationship type DEPENDENT_OF 14

p 2) Identifier Dependency n p Occurs when the weak entity set does not p 2) Identifier Dependency n p Occurs when the weak entity set does not have a candidate key, and its instances are indistinguishable w/o a relationship with other entity (e. g. grade). 3) Referential Dependency n Occurs when a weak entity contains a foreign key of the corresponding strong entity (e. g. essn in Dependent table) p Referential Constraint § A nonnull value of the foreign key attribute in the entity instance must always equal the value of the primary key of an associated strong entity instance. 15

16 16

Many-to-one (N: 1) Relationship 17 Many-to-one (N: 1) Relationship 17

Many-to-many (M: N) Relationship 18 Many-to-many (M: N) Relationship 18

Displaying a recursive relationship p In a recursive relationship type. n n p p Displaying a recursive relationship p In a recursive relationship type. n n p p Both participations are same entity type in different roles. For example, SUPERVISION relationships between EMPLOYEE (in role of supervisor or boss) and (another) EMPLOYEE (in role of subordinate or worker). In following figure, first role participation labeled with 1 and second role participation labeled with 2. In ER diagram, need to display role names to distinguish participations. 19

A Recursive Relationship Supervision` 20 A Recursive Relationship Supervision` 20

Recursive Relationship Type is: SUPERVISION (participation role names are shown) 21 Recursive Relationship Type is: SUPERVISION (participation role names are shown) 21

Notation for Constraints on Relationships p Cardinality ratio (of a binary relationship): 1: 1, Notation for Constraints on Relationships p Cardinality ratio (of a binary relationship): 1: 1, 1: N, N: 1, or M: N n p Participation constraint (on each participating entity type): total (called existence dependency) or partial. n p Shown by placing appropriate numbers on the relationship edges. Total shown by double line, partial by single line. NOTE: These are easy to specify for Binary Relationship Types. 22

Alternative (min, max) notation for relationship structural constraints: p p p Specified on each Alternative (min, max) notation for relationship structural constraints: p p p Specified on each participation of an entity type E in a relationship type R Specifies that each entity e in E participates in at least min and at most max relationship instances in R Default(no constraint): min=0, max=n (signifying no limit) Must have min max, min 0, max 1 Derived from the knowledge of mini-world constraints Examples: n A department has exactly one manager and an employee can manage at most one department. p p n Specify (0, 1) for participation of EMPLOYEE in MANAGES Specify (1, 1) for participation of DEPARTMENT in MANAGES An employee can work for exactly one department but a department can have any number of employees. p p Specify (1, 1) for participation of EMPLOYEE in WORKS_FOR Specify (0, n) for participation of DEPARTMENT in WORKS_FOR 23

The (min, max) notation for relationship constraints Read the min, max numbers next to The (min, max) notation for relationship constraints Read the min, max numbers next to the entity type and looking away from the entity type 24

COMPANY ER Schema Diagram using (min, max) notation 25 COMPANY ER Schema Diagram using (min, max) notation 25

Alternative diagrammatic notation p p ER diagrams is one popular example for displaying database Alternative diagrammatic notation p p ER diagrams is one popular example for displaying database schemas Many other notations exist in the literature and in various database design and modeling tools Appendix A illustrates some of the alternative notations that have been used Unified Modeling Language (UML) class diagrams is representative of another way of displaying ER concepts that is used in several commercial design tools 26

Summary of notation for ER diagrams 27 Summary of notation for ER diagrams 27

Unified Modeling Language (UML) class diagrams p Represent classes (similar to entity types) as Unified Modeling Language (UML) class diagrams p Represent classes (similar to entity types) as large rounded boxes with three sections: n n n p Relationships (called associations) represented as lines connecting the classes n p p Top section includes entity type (class) name Second section includes attributes Third section includes class operations (operations are not in basic ER model) Other UML terminology also differs from ER terminology Used in database design and object-oriented software design UML has many other types of diagrams for software design (see Chapter 12) 28

UML class diagram for COMPANY database schema 29 UML class diagram for COMPANY database schema 29

Other alternative diagrammatic notations 30 Other alternative diagrammatic notations 30

Relationships of Higher Degree p p Relationship types of degree 2 are called binary Relationships of Higher Degree p p Relationship types of degree 2 are called binary Relationship types of degree 3 are called ternary and of degree n are called n-ary In general, an n-ary relationship is not equivalent to n binary relationships Constraints are harder to specify for higherdegree relationships (n > 2) than for binary relationships 31

Discussion of n-ary relationships (n > 2) p p p In general, 3 binary Discussion of n-ary relationships (n > 2) p p p In general, 3 binary relationships can represent different information than a single ternary relationship (see Figure 3. 17 a and b on next slide) If needed, the binary and n-ary relationships can all be included in the schema design (see Figure 3. 17 a and b, where all relationships convey different meanings) In some cases, a ternary relationship can be represented as a weak entity if the data model allows a weak entity type to have multiple identifying relationships (and hence multiple owner entity types) (see Figure 3. 17 c) 32

Example of a ternary relationship 33 Example of a ternary relationship 33

Discussion of n-ary relationships (n > 2) p p If a particular binary relationship Discussion of n-ary relationships (n > 2) p p If a particular binary relationship can be derived from a higher-degree relationship at all times, then it is redundant For example, the TAUGHT_DURING binary relationship in Figure 3. 18 (see next slide) can be derived from the ternary relationship OFFERS (based on the meaning of the relationships) 34

Another example of a ternary relationship 35 Another example of a ternary relationship 35

Displaying constraints on higher-degree relationships p p The (min, max) constraints can be displayed Displaying constraints on higher-degree relationships p p The (min, max) constraints can be displayed on the edges – however, they do not fully describe the constraints Displaying a 1, M, or N indicates additional constraints n n p An M or N indicates no constraint A 1 indicates that an entity can participate in at most one relationship instance that has a particular combination of the other participating entities In general, both (min, max) and 1, M, or N are needed to describe fully the constraints 36

Data Modeling Tools p A number of popular tools that cover conceptual modeling and Data Modeling Tools p A number of popular tools that cover conceptual modeling and mapping into relational schema design. n p POSITIVES: n p Examples: ERWin, S- Designer (Enterprise Application Suite), ER- Studio, etc. Serves as documentation of application requirements, easy user interface - mostly graphics editor support NEGATIVES: Most tools lack a proper distinct notation for relationships with relationship attributes n Mostly represent a relational design in a diagrammatic form rather than a conceptual ER-based design (See Chapter 12 for details) n 37

Some of the Currently Available Automated Database Design Tools COMPANY TOOL FUNCTIONALITY Embarcade ER Some of the Currently Available Automated Database Design Tools COMPANY TOOL FUNCTIONALITY Embarcade ER Studio ro DB Artisan Technologi es Database Modeling in ER and IDEF 1 X Oracle Developer 2000/Designer 2000 Database modeling, application development Popkin Software System Architect 2001 Data modeling, object modeling, process modeling, structured analysis/design Platinum (Computer Associates ) Enterprise Modeling Suite: Erwin, BPWin, Paradigm Plus Data, process, and business component modeling Persistenc e Inc. Pwertier Mapping from O-O to relational model Rational Rose Database administration, space and security management 38 UML Modeling & application generation

Extended Entity-Relationship (EER) Model (in next chapter) p p The entity relationship model in Extended Entity-Relationship (EER) Model (in next chapter) p p The entity relationship model in its original form did not support the specialization and generalization abstractions Next chapter illustrates how the ER model can be extended with n n n Type-subtype and set-subset relationships Specialization/Generalization Hierarchies Notation to display them in EER diagrams 39

Chapter Summary p p p ER Model Concepts: Entities, attributes, relationships Constraints in the Chapter Summary p p p ER Model Concepts: Entities, attributes, relationships Constraints in the ER model Using ER in step-by-step conceptual schema design for the COMPANY database ER Diagrams - Notation Alternative Notations – UML class diagrams, others 40

Mapping an E-R Model to a Relational Model p p 1) The entity sets Mapping an E-R Model to a Relational Model p p 1) The entity sets represented by rectangles becomes relations represented by tables 2) For strong entity sets, attributes represented by ovals become attributes of the relations or column headings of the table n p For weak entity set - all attributes include all the attributes of the weak entity, plus the primary key of the owner entity 3) The table for a relationship set has column headings consisting of the associated entities, plus column for descriptive attributes if any 41

Exercise: create ER-Diagrams a) COURSE(COURSE#, C_TITLE, INS_NAME, TEXT_BOOK, PUBLISHER) b) ENROLLMENT(STUID, COURSE#, STUNAME, COURSETITLE, Exercise: create ER-Diagrams a) COURSE(COURSE#, C_TITLE, INS_NAME, TEXT_BOOK, PUBLISHER) b) ENROLLMENT(STUID, COURSE#, STUNAME, COURSETITLE, GRADE) c) PART(PART#, PART_NAME, DEPARTMENT, PRICE) d) EMPLOYEE(EMPID, EMPNAME, DATE_HIRED, JOB_TITLE, JOB_LEVEL, PROJ#, PROJ_TITLE, DUEDATE, HOURS_WORKED) e) BOOK(ISBN, TITLE, AUTHOR_INSTITUTE, PRICE, PUBLISHER_NAME, PUBLISHER_ADR) f) CUSTOMER(CUSTID, CUSTNAME, PHONE#, STREET, CITY, STATE, ZIP) 42

Examples p http: //www. meds-sdmm. dfompo. gc. ca/meds/Prog_Nat/NCIS/Definitio n/Ncis_ER_diagram. gif 43 Examples p http: //www. meds-sdmm. dfompo. gc. ca/meds/Prog_Nat/NCIS/Definitio n/Ncis_ER_diagram. gif 43

44 44

45 45

Data Modeling Tools - Visio p 2007 Visio 2007 Demo: Show It Like It Data Modeling Tools - Visio p 2007 Visio 2007 Demo: Show It Like It Is -- Connect Data to Your Visio Diagram This demo shows how you can use Microsoft Office Visio Professional 2007 to analyze how a process or other area is actually performing by connecting data to the shapes in your diagram. 1/30/2008 Visio 2007 Demo: Create a background and watermark for your drawings Learn how to create a background and watermark for your drawings in Microsoft Office Visio 2007. 1/25/2008 Visio 2007 Demo: Let Data Tell Its Story with Data Graphics In this demo, you’ll see how to use data graphics in your Microsoft Office Visio 2007 diagram to present the right data in the right way and to make your points clearly. 1/30/2008 p Visio 2007 Demo: Give Your Diagram a Makeover by Applying a Theme Use themes in Microsoft Office Visio Professional 2007 to easily add color and style to your diagram and create an attractive, engaging piece. 1/30/2008 Visio 2007 Demo: Get a New Perspective on Data with Pivot. Diagrams In this demo, you’ll see how Pivot. Diagrams can help you get a fresh perspective on your data. 46

Oracle Designer – Oracle Designer p http: //www. oracle. com/technology/produc ts/designer/demos. htm Database Design Oracle Designer – Oracle Designer p http: //www. oracle. com/technology/produc ts/designer/demos. htm Database Design and Generation p p p Creating Entity Diagrams (Viewlet) Creating Database Designs (Viewlet) Working With Server Models (Viewlet) Generating Databases (Viewlet) Capturing Database Designs (Viewlet) 47

Data Modeling Tools Sybase – Power. Designer p http: //www. sybase. com/products/modelingmetadata/powerdesign er/demonstrationvideos p Data Modeling Tools Sybase – Power. Designer p http: //www. sybase. com/products/modelingmetadata/powerdesign er/demonstrationvideos p http: //www. datamodel. org/Power. Designer/ Database Designers the technical video demonstrates: n n n A Walk Through of a Sample Conceptual Data Model Reverse Engineer a PDM from a Database Iterative Bi-level Design with Power. Designer Keeping the Modeling and the Servers Synchronized Download this video: http: //download. sybase. com/presentation/pdvideo/pd_d ba 1. exe 48