376a. Database Design Dept. of Computer Science Vassar College http://www.cs.vassar.edu/~cs376 Class 2 – Entity Relationship model and EER Prof. Billibon Yoshimi 1/17/2019
Who am I Bill Yoshimi Office: 106 Old Laundry Building Phone: 437-5986 Email: yoshimi@cs.vassar.edu Office Hours: 4:15-5:15PM MW Prof. Billibon Yoshimi 1/17/2019
Housekeeping Webpage is outdated. We will basically be following the same outline. Verify that you can login to the CS department Solaris machines. Prof. Billibon Yoshimi 1/17/2019
First Assignment Questions: 3.16, 3.17, 3.18, and 3.21 Print neatly. Due: 9/18 at start of class. Prof. Billibon Yoshimi 1/17/2019
Entity-Relationship Modeling From last class remember Entities model real world objects or processes. Entities have attributes. Attributes can be simple, composite, multi-valued, multi-leveled and stored or derived. Entities are distinguishable from other entities. Every entity must have a unique value for it’s key attribute. May be composite (superkey). May have more than one key. Prof. Billibon Yoshimi 1/17/2019
Relationships Relate two or more entities together. Binary – two entities, Ternary – three entities, N-ary – N entities. Relationships may have attributes. WorksOn(Person, Project, Hours) where hours is the number of hours Person works on Project. Prof. Billibon Yoshimi 1/17/2019
Value Sets of Attributes A: Attribute E: Entity Type V: Value Set A:E -> P(V) P(V) is the power set of V(the set of all subsets of V). Prof. Billibon Yoshimi 1/17/2019
Value Sets of Attributes cont. A(e) : value of attribute A for entity e A(e) is a singleton for SV attributes (has only one element) A(e) may be empty set, single element or multiple element for multivalued attribute. A(e) for composite attribute is Cartesian product (all pairs mapping) of P(V1)xP(V2)xP(V3)… Use (…) and comma separated list to denote composite attribute. Use {…} and comma separated list to denote multi-valued attribute Prof. Billibon Yoshimi 1/17/2019
Value Set of Entity cont. E.g. if a person can have more than one residence and each residence can have more than one phone then the attribute AddressPhone {AddressPhone({Phone(AreaCode,PhoneNumber)}, Address(StreetAddress(Number, Street, ApartmentNumber),City,State,Zip))} Prof. Billibon Yoshimi 1/17/2019
Relationships Relationship type R among N entity types E1…EN is a set of associations among these types. R is a set of ri where each ri is an n tuple of (e1, e2, … en) and each ej in ri is a member of entity type Ej 1<j<N Prof. Billibon Yoshimi 1/17/2019
Example EMPLOYEE DEPARTMENT WORKS_FOR e1 e2 e3 e4 e5 e6 e7 r1 r2 r3 r4 Prof. Billibon Yoshimi 1/17/2019
Degree of a Relationship Model Degree is number of participating Entity Types. In previous example, degree is 2 or binary. (most used form) Ternary relationship type has three Entity Types. (holds more information than 3 binary relationships). Connection trap can occur when 3 binary relations used instead of ternary relation. Prof. Billibon Yoshimi 1/17/2019
Relations as Attributes Example entity type EMPLOYEE Name (Fname, Mname, Lname), SSN, Sex, Address, Salary, Bdate, Department, Supervisor, {WorksOn (Project, Hours)} Department is attribute of entity EMPLOYEE The value set of Department is set of all DEPARTMENT entities. If Employee is attribute of DEPARTMENT, then 2 are constrained to be inverses of each other! Prof. Billibon Yoshimi 1/17/2019
Role Name What is the role of the entity in the relationship. Important when entity type serves multiple roles in a relationship. In SUPERVISION relationship there is a supervisor and supervisee. If an entity participates in multiple relationships a relationship type but in different roles, the relationship type is recursive. Prof. Billibon Yoshimi 1/17/2019
Structural relationship type constraints Cardinality: 1:1, 1:N, N:M constrains the number of relationship instances an entity can participate in. Participation: total and partial Total –every entity in the total set of E must participate in the relationship. (also called the Existence dependency) Partial – some of E must participate. Can be specified as 0<=min<=max for all e in E. Prof. Billibon Yoshimi 1/17/2019
Relationships can have attributes If an attribute’s value is determined by a combination of the participating entities, it should be an attribute of the relationship. Prof. Billibon Yoshimi 1/17/2019
Weak entity types Entities without key attributes Must be associated with an identifying owner. Always has a total participation constraint (can’t exist by itself). Partial key is identifying owner + set of attributes to identify the weak entity for the same owner entity. e.g. DEPENDANT - must be associated with EMPLOYEE (Dname, Bdate,Sex, Relationship). Prof. Billibon Yoshimi 1/17/2019
Entity Relationship Diagrams Prof. Billibon Yoshimi 1/17/2019
How to draw relations Prof. Billibon Yoshimi 1/17/2019
Example of COMPANY database (relationships given on P. 53) Prof. Billibon Yoshimi 1/17/2019
Convention used in diagrams Singular names used for entity types Entity types and relationship types in UPPERCASE. Attributes names have first letter capitalized. Role names are lower case. Prof. Billibon Yoshimi 1/17/2019
Demonstrate Ternary relationship SUPPLIER, PART, and PROJECT SUPPLY Vs. SUPPLIER, PART, PROJECT CAN_SUPPLY, SUPPLIES, USES ! Can have relationships in 2 not in 1 unless we impose other constraints Prof. Billibon Yoshimi 1/17/2019
Problems defining relationships Connection Traps (what dept is the employee in?) COMPANY 1 1 HAS HAS N N DEPT EMPLOYEE Prof. Billibon Yoshimi 1/17/2019
Resolving traps DEPT N 1 HAS HAS 1 N COMPANY EMPLOYEE Prof. Billibon Yoshimi 1/17/2019
Problems with model No relations between an entity and a collection of entity types. No relation between and entity and a relation No inheritance Prof. Billibon Yoshimi 1/17/2019
Enhanced ER Model Uses subclasses Inherits all attributes from superclass Subclass entity is a superclass entity. Accomplished through specialization and generalization Specialization – defining subclasses Generalization – defining common abstractions Prof. Billibon Yoshimi 1/17/2019
Subclasses Subclasses can be disjoint or overlapping. Represent intersection of all superclasses. STUDENT PART-TIME FULL-TIME d PERSON o EMPLOYEE STUDENT Prof. Billibon Yoshimi 1/17/2019
Specialization Constraints Defined by predicates (Grade = 4) Defined by attributes Defined by user Disjoint vs. overlapping. Completeness (total or partial). Prof. Billibon Yoshimi 1/17/2019
Multiple Inheritance Entity class can be subclass of multiple superclasses (inherits attributes from all superclasses) Structure of inheritance Hierarchy (only one subclass/superclass relationship) for each subclass Lattice Prof. Billibon Yoshimi 1/17/2019
Union types N OWNS OWNER M REGISTERED_VEHICLE U PERSON BANK COMPANY OWNER is only subclass of the union (member of exactly one super class.) Prof. Billibon Yoshimi 1/17/2019
Difference between subclasses and categories (unions) Subclasses inherit all attributes of all of the super classes. Categories, subclass inherits from only one superclass. Prof. Billibon Yoshimi 1/17/2019
Pages 409-424 Prof. Billibon Yoshimi 1/17/2019