1 / 74

Chapter 2

Chapter 2. Entity-Relationship Model. Chapter 12 & 13 in Textbook. Database Design. Steps in building a database for an application: 1. Understand the real-world domain being captured. 2. Specify it using a database conceptual model (E/R,OO).

lang
Download Presentation

Chapter 2

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 2 Entity-Relationship Model Chapter 12 & 13 in Textbook

  2. Database Design Steps in building a database for an application: 1. Understand the real-world domain being captured. 2. Specify it using a database conceptual model (E/R,OO). 3. Translate specification to model of DBMS (relational). 4. Create schema using DBMS commands (DDL). 5. Load data (DML). Real-world domain Conceptual model DBMS data model Create Schema (DDL) Load data (DML)

  3. Entity-Relationship Model (E/R) A picture is worth a thousand words The Entity-Relationship model (ER) is a high-level description of the structure of the DB. The Entity-Relationship Diagram (ERD) is a graphical model for representing the conceptual model for the data. A E/R models the DB using three element types: - Entities - Attributes - Relationships

  4. name PROFESSOR ERD Example number SCHOOL 1 DOB 1 1 1 1 (0,1) (1,1) (0,1) dean of (0,4) 1 (0,*) (1,*) operate (1,1) chairs (0,*) M advise teach DEPARTMENT 1 (1,1) 1 (1,*) (1,*) 1 offer (1,1) (1,1) M M (1,1) M N M M 1 enroll-in CLASS belong-to COURSE STUDENT (0,*) (0,*) (1,1) (0,*) (1,1) M code hrs has

  5. Entities & Entity Type Entity is an object that exists and is distinguishable from other objects. e.g. person, company, course, university Entity Type is a set of entities of the same type that share the same properties. e.g. set of all persons, companies, trees, courses STUDENT COURSE

  6. Relationships & RelationshipTypes • A relationship associates 2 or more entities. • A relationship type is a set of associations between entity types. study STUDENT COURSE

  7. Degree of Relationship Type Degree of relationship refers to number of participating entity types in a relationship. • A relationship of degree two (2 entity types) are binary. • A relationship of degree three (3 entity types) are ternary.

  8. Degree of Relationship Type A relationship of degree two (2 entity types) are binary. study STUDENT COURSE

  9. Degree of Relationship Type A relationship of degree three (3 entity types) are ternary. e.g. registration of a student in a course by a staff. register STUDENT COURSE STAFF

  10. Recursive Relationship Recursive relationship is a relationship type where the same entity type participates more than once in a different role. It is a unary relationship. COURSE require

  11. Roles Role indicates the purpose that each participating entity type plays in a relationship. (e.g. prerequisite, requester) COURSE requester prerequisite require

  12. Roles Role can be used when two entities are associated through more than one relationship to classify the purpose of each relationship. manages Manager Branch office BRANCH STAFF Branch office Staff member allocated

  13. Attributes Attributes are descriptive properties for an entity type or a relationship type. All entities in one entity type have the same attributes. name DOB St_no Tel_no STUDENT

  14. Attributes of Entities name DOB name hours St_no number Tel_no study STUDENT COURSE

  15. Attributes of Relationships Start End Object All relationships in one relationship type have the same attributes. Relationships can be distinguished not only by their attributes but also by their participating entities. Employee Company contract

  16. Simple & Composite Attributes Simple attribute is an attribute that have a single value with an independent existence. e.g. salary, age, gender,...

  17. Simple & Composite Attributes Composite attribute is an attribute composed of multiple distinct components, each with an independent existence. e.g. address (street, area, city, post code) name (First name, initial, Last name) phone no. (area code, number, exchange no) initial FName LName Area_cd name DOB no St_no Tel_no EX STUDENT

  18. Single-valued & Multi-valued Attributes Single-valued attribute is an attribute that holds a single value for a single entity. It is not necessarily a simple attribute. e.g. student_no, age, gender,...

  19. Single-valued & Multi-valued Attributes Multi-valued attribute is an attribute that may hold multiple values, of the same type, for a single entity. e.g. tel_no, degrees,… initial FName LName Area_cd name DOB no St_no Tel_no EX STUDENT

  20. Derived Attributes Derived attribute is an attribute that represents a value that is derived from the value of a related attribute,not necessarily in the same entity type. e.g. age is derived from date_of_birth total_cost is derived from quantity*unit_price name DOB St_no Tel_no age STUDENT

  21. Keys Candidate key(CK) is the minimal set of attributes that uniquely identifies an entity. It cannot contain null. e.g. student_no, social_security_no, branch_no… Primary Key(PK) is a candidate key that is selected to uniquely identify each entity. Alternate Key(AK) is a candidate key that is NOT selected to be the primary key.

  22. Keys Example ELEMENT(symbol, name, atomic_no)

  23. Keys Example Candidate Key ELEMENT(symbol, name, atomic_no) Primary Key Alternate Keys

  24. Choice of PK Choice of Primary Key (PK) is based on: • Attribute length • Number of attributes required • Certainty of uniqueness

  25. Primary Key in ERD initial FName LName Area_cd name DOB no St_no Tel_no EX STUDENT age

  26. Keys A key can be: - simple key is a candidate key of one attribute. e.g. student_no, branch_no… - composite key is a candidate key that consists of two or more attributes. e.g. STUDENT (Lname, Fname, Init) CLASS (crs_code, section_no) ADVERT (property_no, newspaperName, dateAdvert)

  27. Composite Key in ERD name Section_no hours crs_code CLASS

  28. Strong & Weak Entity Types A strong entity type is NOT existence-dependent on some other entity type. It has a PK. A weak entity type is an entity type that is existence-dependent on some other entity type. It does not have a PK.

  29. Weak Entity Type • The existence of a weak entity type depends on the existence of a strong entity set; it must relate to the strong entity type via a relationship type called identifying relationship. • The PK of a weak entity set is formed by the PK of its strong entity type, plus a weak entity type discriminator attribute. LName FName dep_no FName emp_no DOB has EMPLOYEE DEPENDENT

  30. Cardinalities Cardinality ratio expresses the number of relationships an entity can participate in. Most useful in describing binary relationship types. For a binary relationship type the mapping cardinality must be one of the following types: – One to one (1:1) – One to many(1:M) – Many to one (M:1) – Many to many (M:N)

  31. One-To-One Relationship PROFESSOR chair DEPARTMENT P1 r1 D002 P2 P3 r2 D001 A professor chairs at most one department; and a department is chaired by only one professor. 1 1 chairs PROFESSOR DEPARTMENT

  32. One-To-Many Relationship PROFESSOR teach COURSE P1 r1 C01 r2 C02 P2 r3 C03 P3 C04 A course is taught by at most one professor; a professor teaches many courses. 1 M teach PROFESSOR COURSE

  33. Many-To-One Relationship CLASS require ROOM C1 r1 R001 C2 r2 R002 C3 r3 R003 R004 A class requires one room; while a room can be scheduled for many classes. M 1 require CLASS ROOM

  34. Many-To-Many Relationship CLASS enroll STUDENT C1 r1 S1 C2 r2 S3 C3 r3 S4 r5 S5 A class enrolls many students; and each student is enrolled in many classes. M N enroll CLASS STUDENT

  35. Multiplicity Multiplicity is the number (range) of possible entities that may relate to a single association through a particular relationship. It is best determined using sample data. Takes the form (min#, max#)

  36. Multiplicity STAFF manage BRANCH SG1 r1 B002 SG2 SG3 r2 B001 1 1 manage STAFF BRANCH (0,1) (1,1)

  37. Multiplicity STAFF oversee PROPERTY SG1 r1 P1 r2 P2 SG2 r3 P14 SG3 P6 1 M oversee STAFF PROPERTY (0,10) (0,*) (0,1)

  38. Multiplicity Newspaper advertise PROPERTY Al-Riyadh r1 P1 r2 P13 Al-Bilad r3 Al-Madinah r4 P6 Al-Sharq P4 M N advertise NEWSPAPER PROPERTY (0,*) (0,*)

  39. Participation Constraints Participation constraints determine whether all or only some entities participate in a relationship. Two types of participation: - Mandatory (total) - Optional (partial)

  40. Participation Constraints • Mandatory (total) (1:*): if an entity’s existence requires the existence of an associated entity in a particular relationship (existence-dependent). e.g. CLASS taught-by PROFESSOR i.e. CLASS is a total participator in the relation. A weak entity always has a mandatory participation constraints but the opposite not always true.

  41. Participation Constraints • Optional (partial) (0:*): if an entity’s existence does not require a corresponding entity in a particular relationship. (Not existence-dependent). e.g. PROFESSOR teach CLASS i.e. PROFESSOR is a partial participator in the relation.

  42. ER Case Study Class exercise: Banks Database • Each bank has a unique name. • Each branch has a number, name, address (number, street, city), and set of phones. • Customer includes their name, set of address (P.O. Box, city, zip code, country), set of phones, and social security number. • Accounts have numbers, types (e.g. saving, checking) and balance. Other branches might use the same designation for accounts. So to name an account uniquely, we need to give both the branch number to which this account belongs to and the account number. • Not all bank customers must own accounts and a customer may have at most 5 accounts in the bank. • An account must have only one customer. • A customer may have many accounts in different branches.

  43. ER Case Study Homework: Television Series Database A Television network wishes to create a database to keep track of its TV series. A television series has one or more episode. Television series identified by name and season number, and includes their production company name and Num_of_Episodes ( i.e. total number of episodes in a specific season of a series ). Episode of a specific season of a series is identified by episode number and has a title and a length. No episode can exist without a corresponding television series. Also each episode has only one writer. A writer is identified by name, and also has birth date and a literary agency that represents him or her. An actor appears as a performer in a television series or a guest star on an episode. An actor is identified by name and also has a nationality and birth date. An actor plays a particular character in a television series or episode.

  44. Problems with ER ModelConnection Traps Connection traps are problems that occur due to misinterpretation of the meaning of certain relationships. Types of connection traps: • Fan Trap • Chasm Trap

  45. Fan Trap STAFF has DIVISION operate BRANCH SG1 r1 D1 r4 B002 SG3 r2 r5 B003 SG2 r3 D2 r6 B004 1 1 operate has DIVISION M M BRANCH STAFF

  46. Fan Trap DIVISION operate BRANCH has STAFF D1 r1 B002 r4 SG1 r2 B003 r5 SG3 D2 r3 B004 r6 SG2 1 M has operate BRANCH M 1 STAFF DIVISION

  47. Fan Trap Fan trap where a model represents a relationship between entity types, but the pathway between certain entity occurrence is ambiguous. Exists where 2 or more 1:M relationships fan out from the same entity.

  48. Chasm Trap BRANCH has STAFF oversee PROPERTY B001 r1 SG1 r4 P1 B003 r2 SG2 P14 B002 r3 SG3 r6 P5 1 M oversee has STAFF (1,1) (0,*) M 1 PROPERTY (0,1) (1,*) BRANCH

  49. Chasm Trap BRANCH has STAFF oversee PROPERTY B001 r1 SG1 r4 P1 B003 r2 SG2 P14 B002 r3 SG3 r5 P5 offer r6 r7 r8 1 M oversee has STAFF (0,*) M (1,1) 1 (0,1) BRANCH (1,*) 1 M PROPERTY offer

  50. Chasm Trap Chasm trap where a model suggests the existence of a relationship between entity types, but the pathway does not exist between certain entities. Exists when partial participating entity is part of the pathway between related entities.

More Related