Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS34311 The Entity- Relationship Model. CS34312 Database Design Stages Application Requirements Conceptual Design Logical Design Physical Design Conceptual.

Similar presentations


Presentation on theme: "CS34311 The Entity- Relationship Model. CS34312 Database Design Stages Application Requirements Conceptual Design Logical Design Physical Design Conceptual."— Presentation transcript:

1 CS34311 The Entity- Relationship Model

2 CS34312 Database Design Stages Application Requirements Conceptual Design Logical Design Physical Design Conceptual Schema Logical Schema Physical Schema

3 CS34313 Conceptual Design What is Conceptual Design? Concise representation of our DB application requirements Why Conceptual Design ? It helps us to understand application requirements better It helps us to communicate our understanding of application It helps us to come up with a ‘good’ design

4 CS34314 Conceptual Design Conceptual Models ER (Entity Relationship) Model, UML (Unified Modeling Language), ORM (Object Role Modeling), etc ER Model Structures: entities and relationships Constraints An ER schema is represented as an ER diagram.

5 CS34315 ER Model: Entity Types and Attributes Entity: “Object” Entity Type: “Class” Attribute: property of an entity, has a domain In ER diagrams Entity Type  rectangle Attribute  Oval. Entity Type Student with attributes (sNumber, sName, sAge)

6 CS34316 ER Example Consider DB instance with 3 students (1, Joe, 21), (2, Mary, 20), (3, Emily, 20)

7 CS34317 ER Model: Complex Attributes Composite Attribute: addressMultivalued Attribute: major Student entity type with all its attributes

8 CS34318 ER Model: Relationship Types Relationship: Association between entities Relationship Type: Class of relationships Representation: Use a diamond shape Relationship type HasTaken to represent Courses taken by Students

9 CS34319 ER Model: Relationship Types with Attributes Relationship HasTaken has an attribute project which is the project the Student did for the Course

10 CS343110 Example: Relationship Instances students {Hong, Song}, courses {DB1, DB2}, and relationships {(Hong, DB1, 98), (Song, DB1, 99), (Hong, DB2, 97)}

11 CS343111 More relationship types Example : Model the relationship Supplier supplies Products to Consumers for a given price at a given quantity. How would you model this ?

12 CS343112 More relationship types Model the relationship Supplier supplies Products to Consumers Could we make two binary (or three binary) relationships instead?

13 CS343113 Binary vs. Ternary Relationships What about following binary relationships : S “can-supply” P, C “needs” P, and C “deals-with” S No combination of binary relationships is an adequate substitute: Together 3 binary relationships don’t imply that C has agreed to buy P from S. Also, how could we record qty and price?

14 CS343114 Recursive Relationship Types and Roles Recursive relationship type : Part-Subpart Roles: There are Parts that play the role of superPart There are Parts that play the role of subPart

15 CS343115 ER Model so far Structures Entity Types Relationship Types Binary, ternary, n-ary Recursive Attributes For entity types and relationship types Simple, composite, multivalued Roles

16 CS343116 ER Model: Key Constraints How : Underline the key attribute/attributes Key for Student is sNumber Key for Movie is Note: We can represent key for an entity type consisting of more than 1 attribute (e.g.: Movie) We cannot represent multiple keys for an entity type (eg: key for Student can be either sNumber or sName)

17 CS343117 ER Model: Cardinality Constraints How : Expressed using (min, max) Student can take >= 2 and <= 3 Courses Course can have >= 0 and <= * (infinity) Students min and max are non-negative integers max > min

18 CS343118 Cardinality Constraints 1:1 relationship type: A Dept has exactly one Manager, A Person can manage at most one Dept Person pNumber pName Dept dNumber dName Manages

19 CS343119 Cardinality Constraints 1:1 relationship type: A Dept has exactly one Manager, A Person can manage at most one Dept

20 CS343120 Cardinality Constraints 1:1 relationship type: A Dept has exactly one Manager, A Person can manage at most one Dept

21 CS343121 Cardinality Constraints 1:many (1:n) relationship type: A Person works for exactly one Dept, A Dept can have any number of Persons Person pNumber pName Dept dNumber dName Works For

22 CS343122 Cardinality Constraints 1:many (1:n) relationship type: A Person works for exactly one Dept, A Dept can have any number of Persons

23 CS343123 Cardinality Constraints 1:1 relationship type: A Dept has exactly one Manager, A Person can manage atmost one Dept 1:many (1:n) relationship type: A Person works for exactly one Dept, A Dept can have any number of Persons

24 CS343124 Cardinality Constraints many:many (m:n) relationship type: A Person works for one or more Depts, A Dept can have any number of Persons Person pNumber pName Dept dNumber dName Works For

25 CS343125 Cardinality Constraints many:many (m:n) relationship type: A Person works for one or more Depts, A Dept can have any number of Persons

26 CS343126 Cardinality Constraints for n-ary relationships A Supplier supplies at least one Product to some Consumer Supplier sName sLoc Consumer cName cLoc Supply price Product pName pNumber qty

27 CS343127 Cardinality Constraints for n-ary relationships A Supplier supplies at least one Product to some Consumer

28 CS343128 Cardinality Constraints for n-ary relationships What about the following constraints : (1) A Consumer gets a Product from only one Supplier (2) Each Supplier supplies exactly 2 Products

29 CS343129 Cardinality Constraints for Recursive Relationships A Part can be subpart of one superPart A Part can have many subParts Contains Part pName pNumber subPartsuperPart quantity

30 CS343130 Cardinality Constraints for Recursive Relationships A Part can be subpart of one superPart A Part can have many subParts

31 CS343131 Cardinality Constraints for Recursive Relationships A Part can be subpart of one superPart A Part can have many subParts A Part can be subpart of many superParts A Part can have many subParts

32 CS343132 Cardinality Constraints for Recursive Relationships A Part can be subpart of one superPart A Part can have many subParts A Part can be subpart of many superParts A Part can have many subParts

33 CS343133 ER Model Constraints Summary Key Constraints Cardinality Constraints Expressed using (min, max) Binary relationship types are called 1:1, 1:many, many:many

34 CS343134 An Application Example Courses offered in CS Dept, WPI, in B term What entity types? Student, Professor, Course, GradStudent Attributes and key constraints for entity types ? What relationship types? Cardinality for relationship types ?

35 CS343135 An Application Example Courses offered in CS Dept, WPI, in B term Next time …


Download ppt "CS34311 The Entity- Relationship Model. CS34312 Database Design Stages Application Requirements Conceptual Design Logical Design Physical Design Conceptual."

Similar presentations


Ads by Google