This action might not be possible to undo. Are you sure you want to continue?
Text: Chapter 2
© G. Tsiknis; Based on Ramakrishnan & Gehrke, DB Management Systems
given a problem description, create an Entity-relationship
diagram with the correct entities and relationships that accurately model the problem’s data given a problem domain (description) that contains entities that depend on other entities, or inherit from other entities or have n-ary relationships with other entities, create an ER model that accurately represent them given a problem description, identify alternative representations of the problem concepts and evaluate the choices compare alternative ER models for the same domain and identify their strengths and weaknesses
Unit 2 2
covered in CICS 505 Conceptual Database Design produces a high level description of data (semantic models) Logical Database Design converts conceptual design into a DB schema (logical schema) Schema Refinement restructuring to satisfy desirable properties (normalization) Physical Database Design deals with how the instances (actual data) will be stored on disk Application & Security Design general application design applications are restricted to only access data that they need Unit 2 3 .Database Design Consists of 6 steps: Requirements Elicitation & Analysis common to all application designs.
Conceptual Database Design Main goal: Given the requirements for an application. but avoid irrelevant nouns e. a prof teaches a course 2. Information about these entities and relationships that should be stored in the database Integrity constraints or business rules that hold For relational databases. Often.. “At UBC.. Unit 2 4 . We have 1000’s of courses…” Relationships are statements about 2 or more objects. The enterprise data is usually represented by an ER diagram. e.g. we have full-time and part-time students. We store such information in our computer. identify: 1. the ER Model is used at this stage.g. verbs. Entities and relationships in the application’s domain Entities are usually nouns. 3.
anyway!) Each attribute has a domain. float. colour) Each entity set has a key. whose data is important for the application.g. (e. 5 . An entity is described using a set of attributes. int. (Until we consider ISA hierarchies.ER Model Basics: Entities Entity: Real-world object distinguishable from other objects.g. date... E.. All entities in an entity set have the same set of attributes. Unit 2 SIN name Addr Employee Entity Set: A collection of similar entities. all employees.
don’t worry about them) Street House # City Address Postal code Province Unit 2 6 . taken collectively. identify uniquely an entity in an entity set. A superkey is a key plus zero or more other attributes in the entity set A primary key is the key chosen as the principal means to identify entities in an entity set Only primary keys are shown in ER diagrams (underlined attributes) We’ll discuss superkeys when we consider normal forms (for now.Keys Distinguish entities A key is the minimal set of one or more attributes which.
ER Model Basics (Cont. etc. .... Degree or arity: # of entity sets in the relationship (binary. or in different “roles” in the same relatioship set. en En o Same entity set could participate in different relationship sets. John works in Marketing department. A relationship set may have descriptive attributes (like since).) Unit 2 7 1 . An n-ary relationship set R relates n entity sets E1 . Relationship Set: Collection of similar relationships. E. each relationship in R involves entities e1 E1.) since name ssn phone Employee Works_In did dname budget Department name ssn phone Employee supervisor subordinate Reports_To Relationship: Association among two or more entities. En.... ternary.g.
R can be : one-to-one from A to B: an entity in A is associated with at most one entity in B and vice versa e. Let R be a relationship set between sets A and B. B: driver's license A B Unit 2 8 .g.Cardinality Ratios (Mapping Cardinalities) A cardinality ratio for a relationship set specifies the number of relationships in the set that an entity can participate in. A: driver.
B: courses Unit 2 9 2 .g.g.Cardinality Ratios (cont’) one-to-many from A to B: an entity in A is associated with any number of entities in B an entity in B is associated with at most one entity in A e. B: employee A B many-to-one from A to B: switch A and B above many-to-many from A to B: an entity in A is associated with any number of entities in B and vice versa e. A: manager.g. A: mother. B: children e. A: students.
e.Key Constraints The restriction imposed by a 1-to-1 and 1-to-many ratios are examples of key constraint. A key constraint is shown with an arrow in the ER diagram. since name ssn phone did dname budget Employee Manages Department or Country Has Capital Unit 2 10 . Important on insertions I.
A brief note on notation The ER notation we use can be read: “if you know the entity at the tail of the arrow. be careful when using other sources! Unit 2 11 . then you know the relationship (and the other entities involved)” since name ssn phone did dname budget Employee Manages Department Other notations put the arrows in other places.
An entity’s participation can be total (everyone participates) or partial (some may not participate) A total participation is a participation constraint and it is shown with a thick line in ER diagrams Important on deletions i.Participation Constraints Participation : Indicates if all entities participate in the relationship. participation of Departments in Manages is total (thick line) o Every department must appear in some relationship in the Manages set since name dname phone Employee ssn did Manages Department budget Works_In Unit 2 since 12 .e.
Unit 2 13 . R's primary key is: TYPE OF R one-to-one one-to-many from A to B many-to-many PRIMARY KEY OF R primary key of A or primary key of B primary key of B primary key of A + primary key of B R may have its own attributes.Primary Keys of Relationship Sets Let R be a relationship set between sets A and B. in addition to the key that inherits from the entities.
Line Types Review Plain lines mean many to many and partial participation: Employee Works_In Department (many to many) Arrows mean the arrow side has a cardinality of one Employee Manages Department (one any line. 4. 5 . arrow or not Employee Unit 2 to many) Thick line requires total participation and can be added to Manages Department (one to many) 14 3.
Weak entity set must have total participation in this identifying relationship set. many weak entities). name allowance ssn phone pname bday Employee Unit 2 has Dependent 15 6 . Think of this as a “belongs to” relationship.Weak Entities A weak entity can be identified uniquely only by considering the primary key of another (owner) entity. Owner entity set and weak entity set must participate in a one-to-many relationship set (one owner. Weak entity sets and their identifying relationship sets are shown with thick lines.
Generaligation/Specialization (ISA relationships) As in C++. If we declare A ISA B. attributes can be inherited. or other PLs. every A entity is also considered to be a B entity. name ssn phone Employee hourly_wages hours_worked ISA contractid Hourly_Emp Contract_Emp Unit 2 16 .
To restrict entities that participate in a relationship.Specialization Types Overlap constraints: Specializations can be: Disjoint : a superclass entity may not belong to more than a single subclass Overlapping : subclasses may overlap Covering constraints: Specializations can be: Total : a superclass entity must belong to some subclass Partial : some superclass entity may not be in any subclass Reasons for using ISA: To add descriptive attributes specific to a subclass. Unit 2 17 .
ternary relationship: enrolls is a distinct relationship. if we want Unit 2 18 7 . with a descriptive attribute. student enrolls section Aggregation allows us to treat a relationship set as an entity set for purposes of participating in (other) relationships. appears-in report Aggregation vs.Aggregation Used when we have to grade model a relationship involving another relationship set. we can restrict each enrollment (and grade ) to appear in at most one report.
e. domain constraints dependencies Unit 2 19 .Conceptual Design Using the ER Model Design choices: Should a concept be modeled as an entity or an attribute? Should a concept be modeled as an entity or a relationship? Identifying relationships: Binary or ternary? Aggregation? A lot of data semantics can (and should) be captured But some constraints cannot be captured in ER diagrams o o Constraints in the ER Model: i.
Attribute Should address be an attribute of Employees or an entity (connected to Employees by a relationship)? Depends upon the use we want to make of address information the semantics of the data: o If we have several addresses per employee. Unit 2 20 . then these should simply be attributes. one province. one postal code. etc.Entity vs. one city. o If an employee has only one street address. address must be an entity (since attributes cannot be set-valued).
) Works_In2 does not allow an employee to work in a department for two or more periods.Entity vs. Solution: change name ssn Employee phone from to dname did budget Department Works_In2 name ssn Employee phone Works_In3 did dname budget Department descriptive attributes into entities. Attribute (Cont. department) with more than one set of values for the descriptive attributes. We want to associate the same pair (employee. Unit 2 from Duration to 21 .
If a manager gets a budget that covers all managed depts? since name ssn Employee phone dbudget did dname budget Department Manages2 name ssn Employee phone redundancy misleading dbudget ISA Solution: Define a new entity for managers Unit 2 since did Manages3 dname budget Department 22 Manager . Relationship First ER diagram is OK if a manager gets a separate discretionary budget for each dept.Entity vs.
Ternary Relationships name ssn phone Employee Covers Policies policyid name ssn Employee Purchaser phone cost pname age pname age If each policy is Dependent owned by just 1 employee: Bad design Key constraint on Policies would mean policy can only cover 1 dependent! Dependent What are the additional constraints in the 2nd diagram? Unit 2 Beneficiary Better design policyid Policies cost 23 .Binary vs.
Binary vs. a person cannot have more than one drink in the same bar 24 Unit 2 . how would we record date? Aggregation can be used instead of a ternary relation if need to impose additional constraints: I. Aggregation Previous example: two binary relationships were better than one ternary relationship. No combination of binary relationships is an adequate substitute: P “likes” D.e. and has descriptive attribute date. Also. An example in the other direction: a ternary relation Drinks relates entity sets Person. Ternary Relationships vs. Bar and Drink. and B “provides” D does not imply that P drinks D in B. P “visits” B.
Yields a high-level description of data to be stored Constructs are expressive. close to the way people think about their applications. Unit 2 25 . Note: There are many variations on ER model. ISA relationships. Some additional constructs: weak entities. relationships.Summary of Conceptual Design Conceptual design follows requirements analysis. and aggregation. and attributes (of entities and relationships). ER model popular for conceptual design Basic constructs: entities.
) Several kinds of integrity constraints can be expressed in the ER model: key constraints.Summary of ER (Cont. Some constraints (notably. Constraints play an important role in determining the best database design for an enterprise. Unit 2 26 . and overlap/covering constraints for ISA relationships. functional dependencies) cannot be expressed in the ER model. Some foreign key constraints are also implicit in the definition of a relationship set. participation constraints.
Common choices include: entity vs. There are often many ways to model a given scenario! Analyzing alternatives can be tricky. Functional dependencies and normalization techniques are especially useful (see later).) ER design is subjective. attribute entity vs. relationship binary or n-ary relationship whether or not to use ISA hierarchies whether or not to use aggregation Ensuring good database design: resulting relational schema should be analyzed and refined further. Unit 2 27 . especially for a large enterprise.Summary of ER (Cont.
This action might not be possible to undo. Are you sure you want to continue?
We've moved you to where you read on your other device.
Get the full title to continue listening from where you left off, or restart the preview.