Carnegie Mellon Carnegie Mellon Univ. Dept. of Computer Science Database Applications C. Faloutsos E-R diagrams
Carnegie Mellon C. Faloutsos2 Overview concepts –Entities –Relationships –Attributes –Specialization/Generalization –Aggregation turning E-R diagrams to tables
Carnegie Mellon C. Faloutsos3 Tools Entities (‘entity sets’) Relationships (‘rel. sets’) and mapping constraints attributes NM P
Carnegie Mellon C. Faloutsos4 Example Students, taking courses, offered by instructors; a course may have multiple sections; one instructor per course nouns -> entity sets verbs -> relationships
Carnegie Mellon C. Faloutsos5 STUDENT name ssn... INSTRUCTOR issn
Carnegie Mellon C. Faloutsos6 STUDENT name ssn... COURSE c-id c-name but: sections of course (with different instructors)? INSTRUCTOR issn
Carnegie Mellon C. Faloutsos7 COURSE c-id INSTRUCTOR issn STUDENT ssn SECTION s-id but: s-id is not unique...
Carnegie Mellon C. Faloutsos8 COURSE c-id INSTRUCTOR issn STUDENT ssn SECTION s-id takes N M
Carnegie Mellon C. Faloutsos9 COURSE c-id INSTRUCTOR STUDENT SECTION s-id takes N M N 1 teaches
Carnegie Mellon C. Faloutsos10 Cardinalities 1 to 1 (example?) 1 to N N to M
Carnegie Mellon C. Faloutsos11 COURSE c-id INSTRUCTOR STUDENT SECTION s-id takes N M N 1 teaches has N 1
Carnegie Mellon C. Faloutsos12 More details ‘weak’ entities: if they need to borrow a unique id from a ‘strong entity - DOUBLE box. ‘c-id’ + ‘s-id’: unique id for SECTION discriminator (eg., ‘s-id’) COURSE c-id SECTION s-idhas N 1
Carnegie Mellon C. Faloutsos13 More details self-relationships - example?
Carnegie Mellon C. Faloutsos14 EMPLOYEE manages 1 N
Carnegie Mellon C. Faloutsos15 More details 3-way and k-way relationships? EMPLOYEE uses PROJECT TOOL N M P
Carnegie Mellon C. Faloutsos16 More details - attributes candidate key (eg., ssn; employee#) primary key (a cand. key, chosen by DBA) superkey (eg., (ssn, address) ) multivalued or set-valued attributes (eg., ‘dependents’ for EMPLOYEE) derived attributes (eg., 15% tip)
Carnegie Mellon C. Faloutsos17 More details: in the text: (eg., ‘total participation’) INSTRUCTOR SECTION 0:N 1:1 teaches
Carnegie Mellon C. Faloutsos18 Overview concepts –Entities –Relationships –Attributes –Specialization/Generalization –Aggregation turning E-R diagrams to tables
Carnegie Mellon C. Faloutsos19 Specialization eg., students: part time (#credit- hours) and full time (major) STUDENT name ssn PT-STUDENT #credits FT-STUDENT major IS-A
Carnegie Mellon C. Faloutsos20 Observations Generalization: exact reverse of ‘specialization’ attribute inheritance could have many levels of an IS-A hierarchy
Carnegie Mellon C. Faloutsos21 Aggregation CPU HD treat a relationship as an entity rarely used N M MAKER
Carnegie Mellon C. Faloutsos22 Overview concepts –Entities –Relationships –Attributes –Specialization/Generalization –Aggregation turning E-R diagrams to tables
Carnegie Mellon C. Faloutsos23 COURSE c-id INSTRUCTOR STUDENT SECTION s-id takes N M N 1 teaches has N 1 grade
Carnegie Mellon C. Faloutsos24 Strong entities just list the attributes, and underline the primary key, eg. STUDENT(ssn, name, address)
Carnegie Mellon C. Faloutsos25 Multivalued attributes Eg., EMPLOYEE with many dependents: a new table, with (ssn, dependent-name)
Carnegie Mellon C. Faloutsos26 Relationships get primary keys all involved entities primary key - depends on cardinality –1 to 1: either eg EMPLOYEE( ssn, empno, name,...) –1 to N: the key of the ‘N’ part eg. TEACHES( issn, c-id, s-id) –N to M: both keys - eg TAKES( ssn, c-id, s-id, grade)
Carnegie Mellon C. Faloutsos27 Relationships 1 to N: no need for separate table - eg., SECTION( issn, room-num, c-id, s-id) instead of SECTION1(c-id, s-id, room-num) TEACHES(issn, c-id, s-id) for rel. between strong and corresponding weak entity, no need for table, at all!
Carnegie Mellon C. Faloutsos28 Generalization/Spec. Two solutions: - one table for each or - no table for super-entity (pros and cons?)
Carnegie Mellon C. Faloutsos29 Generalization/Special. Eg., STUDENT(ssn, name, address) PT-STUDENT( FT-STUDENT(
Carnegie Mellon C. Faloutsos30 Generalization/Special. Eg., STUDENT(ssn, name, address) PT-STUDENT( ssn, num-credits) FT-STUDENT( ssn, major)
Carnegie Mellon C. Faloutsos31 Generalization/Special. no super-entity: [STUDENT(ssn, name, address)] PT-STUDENT( ssn, num-credits FT-STUDENT( ssn, major
Carnegie Mellon C. Faloutsos32 Generalization/Special. no super-entity: [STUDENT(ssn, name, address)] PT-STUDENT( ssn, num-credits, name, address) FT-STUDENT( ssn, major, name, address)
Carnegie Mellon C. Faloutsos33 Aggregation make table, with primary keys of all involved entities
Carnegie Mellon C. Faloutsos34 Overview concepts –Entities –Relationships –Attributes –Specialization/Generalization –Aggregation turning E-R diagrams to tables
Carnegie Mellon C. Faloutsos35 Summary E-R Diagrams: a powerful, user-friendly tool for data modeling: –Entities (strong, weak) –Attributes (primary keys, discriminators, derived, multivalued) –Relationships (1:1, 1:N, N:M; multi-way) –Generalization/Specialization; Aggregation
Carnegie Mellon C. Faloutsos36 Summary - cont’d (strong) entity set weak entity set relationship set identifying rel. set for weak entity attribute multivalued attribute derived attribute
Carnegie Mellon C. Faloutsos37 Summary - cont’d primary key A discriminator A cardinalities N M with limits l:h l’:h’ IS-A total generalization (e.t.c. - see book for alternative notations)
Carnegie Mellon C. Faloutsos38 Conclusions E-R Diagrams: a powerful, user-friendly tool for data modeling.