Chaptr 3: Entity Rlationship Modl Databas Dsign Procss Us a high-lvl concptual data modl (ER Modl). Idntify objcts of intrst (ntitis) and rlationships btwn ths objcts Idntify constraints (conditions) End rsult is an E-R Diagram that capturs all ntity, rlationship typs and constraints Figur 3. Phass of Databas Dsign
Miniworld DBMS-indpndnt DBMS-spcific Functional Rquirmnts FUNCTIONAL ANALYSIS High-lvl Transaction Spcification APPLICATION PROGRAM DESIGN REQUIREMENTS COLLECTION AND ANALYSIS Databas Rquirmnts CONCEPTUAL DESIGN Concptual Schma (In a high-lvl data modl) LOGICAL DESIGN (DATA MODEL MAPPING) Logical (Concptual) Schma (In th data modl of a spcific DBMS) PHYSICAL DESIGN Figur 3. A simplifid diagram to illustrat th main phass of databas dsign. TRANSACTION IMPLEMENTATION Intrnal Schma Application Programs
Exampl Databas Application (Company Databas) Company organizd into DEPARTMENTs. Each dpartmnt has uniqu nam and a particular mploy who manags th dpartmnt. Start dat for th managr is rcordd. Dpartmnt may hav svral locations. A dpartmnt controls a numbr of PROJECTs. Projcts hav a uniqu nam, numbr and a singl location. Company s EMPLOYEEs nam, ssno, addrss, salary, sx and birth dat ar rcordd. An mploy is assignd to on dpartmnt, but may work for svral projcts (not ncssarily controlld by hr dpt). Numbr of hours/wk an mploy works on ach projct is rcordd; Th immdiat suprvisor for th mploy. Employ s DEPENDENTs ar trackd for halth insuranc purposs (dpndnt nam, birthdat, rlationship to mploy). Figur 3.2: ER Diagram
Figur 3.2 ER schma diagram for th company databas. Fnam Minit Lnam Numbr Nam Addrss N WORKS_FOR Nam Locations Sx Salary Ssn Bdat EMPLOYEE NumbrOfEmploys StartDat MANAGES DEPARTMENT CONTROLS N Hours suprvisor suprvis WORKS_ON N PROJECT SUPERVISION N Nam Location DEPENDENTS_OF Numbr N DEPENDENT Nam Sx BirthDat Rlationship
Entitis and Attributs Entity: an objct in th ral world with an indpndnt xistnc. Attribut: Proprty that dscribs an aspct of th ntity. Figur 3.3 Attribut typs: Simpl vs Composit (Figur 3.4) Singl-valud vs Multi-valud (.g. Locations for DEPARTMENT) Stord vs Drivd (.g. NumbrOfEmploys for DEPARTMENT) Figur 3.5: xampl of a complx attribut with multi-valud and composit componnts Null valus for attributs: Not applicabl, Unknown (Missing; not known if applicabl)
Figur 3.3 Two ntitis, an mploy and a company c, and thir attribut valus. Nam = John Smith Nam = Sunco Oil Addrss = 23 Kirby, Houston, Txas 7700 c Hadquartrs = Houston Ag = 55 HomPhon = 73-749-2630 Prsidnt = John Smith
Figur 3.4 A hirarchy of composit attributs; th StrtAddrss componnt of an Addrss is furthr composd of Numbr, Strt, and ApartmntNumbr. Addrss StrtAddrss City Stat Zip Numbr Strt ApartmntNumbr
Figur 3.5 A complx attribut AddrssPhon with multivalud and composit componnts. {AddrssPhon( {Phon(AraCod,PhonNumbr)}, Addrss(StrtAddrss(Numbr,Strt,ApartmntNumbr), City,Stat,Zip) ) }
Entity Typs, Valu Sts, Ky Attributs An ntity typ dfins a st of ntitis that hav th sam attributs. S Figur 3.6 Rctangular box in ER Diagram dnots Entity Typs Ovals dnot Attributs doubl-ovals: multi-valud attribut tr structurd ovals: composit attribut Entity St = St of all ntitis of th sam typ. Ky Attributs: uniquly idntify ach ntity within an ntity st (ths ar undrlind in th ER Diagram) Valu Sts: or Domains for attributs. A: E -> P(V) A:attribut, E:Entity st, V: Valu st V = P(V) x... x P(Vn) for composit attributs A() dnots th valu of attribut A for ntity Figur 3.7 Car Entity Typ
Figur 3.6 Two ntity typs namd EMPLOYEE and COMPANY, and som of th mmbr ntitis in th collction of ntitis (or ntity st) of ach typ. ENTITY TYPE NAME: EMPLOYEE Nam, Ag, Salary COMPANY Nam, Hadquartrs, Prsidnt c (John Smith, 55, 80k) (Sunco Oil, Houston, John Smith) ENTITY SET: (EXTENSION) 2 (Frd Brown, 40, 30K) 3 (Judy Clark, 25, 20K) c 2 (Fast Computr, Dallas, Bob King)
Figur 3.7 Th CAR ntity typ, with two ky attributs Rgistration and VhiclID. Multivalud attributs ar shown btwn st bracs {}. Componnts of a composit attribut ar shown btwn parnthss (). CAR Rgistration(RgistrationNumbr, Stat), VhiclID, Mak, Modl, Yar, {Color} car ((ABC 23, TEXAS), TK629, Ford Mustang, convrtibl, 998, {rd, black}) car 2 ((ABC 23, NEW YORK), WP9872, Nissan Maxima, 4-door, 999, {blu}) car 3 ((VSY 720, TEXAS), TD729, Chryslr LBaron, 4-door, 995, {whit, blu})
Initial dsign of th COMPANY DATABASE Figur 3.8 4 ntity typs: DEPARTMENT EMPLOYEE PROJECT DEPENDENT Not a prfct dsign! bcaus it capturs rlationships btwn ntitis as attributs (in gnral not a good ida)
Figur 3.8 Prliminary dsign of ntity typs for th COMPANY databas whos rquirmnts ar dscribd in Sction 3.2. DEPARTMENT Nam, Numbr, {Locations}, Managr, ManagrStartDat PROJECT Nam, Numbr, Location, ControllingDpartmnt EMPLOYEE Nam (FNam, MInit, LNam), SSN, Sx, Addrss, Salary, BirthDat, Dpartmnt, Suprvisor, {WorksOn (Projct, Hours)} DEPENDENT Employ, DpndntNam, Sx, BirthDat, Rlationship
Rlationships, Rols, Structural Constraints Rlationship typ: R among n Entity typs E,..., En dfins a st of associations among ntitis from ths typs. ach association will b dnotd as: (,..., n) whr i blongs to Ei, <= i <= n. x. WORKS_FOR rlationship in Figur 3.9 Dgr of rlationship = n (usually n = 2, binary rlationship) Trnary rlationship: Figur 3.0 Rlationships as attributs (.g. Dpt -- Empl rlationship can b viwd as two attributs on in Dpt. and th othr in Empl)
Figur 3.9 Som instancs of th WORKS_FOR rlationship btwn EMPLOYEE and DEPARTMENT. EMPLOYEE WORKS_FOR DEPARTMENT r 2 r 2 d 3 r 3 d 2 4 r 4 d 3 5 6 r 5 7 r 6 r 7
Figur 3.0 Som rlationship instancs of a trnary rlationship SUPPLY. SUPPLIER SUPPLY PROJECT s r s 2 r 2 j r 3 j 2 PART r 4 j 3 r 5 p p 2 r 6 p 3 r 7
Rol nams Each ntity participating in a rlationship has a ROLE..g. Employ plays th rol of workr and Dpartmnt plays th rol of mployr in th WORKS_FOR rlationship typ Rol nams ar mor important in rcursiv rlationships x. Figur 3.
Figur 3. Th rcursiv rlationship SUPERVISION, whr th EMPLOYEE ntity typ plays th two rols of suprvisor () and suprvis (2). EMPLOYEE SUPERVISION r 2 2 2 r 2 3 4 2 r 3 5 2 r 4 6 7 2 r 5 2 r 6
Structural Constraints on Rlationships 2 typs: Cardinality Ratio Constraint (-, -N, M-N) Participation Constraint * total participation (xistnc dpndncy) * partial participation Figurs 3.2 and 3.3 In ER Diagrams: total participation is dnotd by doubl lin and partial participation by singl lin cardinality ratios ar mntiond as labls of dgs
Figur 3.2 Th : rlationship MANAGES, with partial participation of mploy and total participation of DEPARTMENT. EMPLOYEE MANAGES DEPARTMENT 2 r d 3 r 2 d 2 4 5 r 3 d 3 6 7
Figur 3.3 Th M:N rlationship WORKS_ON btwn EMPLOYEE and PROJECT. EMPLOYEE WORKS_ON r PROJECT r 2 2 p 3 r 3 p 2 4 r 4 p 3 r 5 p 4 r 6 r 7
Attributs of rlationships:.x. Hours attribut for WORKS_ON rlationship If rlationship is -N or -, ths attributs can b b migratd to th ntity sts involvd in th rlationship. -N: migrat to N sid -: migrat to ithr sid
Wak Entity Typs: Entity Typs that do not hav ky attributs. Such ntitis ar idntifid by bing rlatd to othr ntity sts calld idntifying ownr. This rlationship is calld idntifying rlationship. Partial ky: attributs that uniquly idntify ntitis within th idntifying rlationship. A wak ntity typ always has TOTAL participation. Ex. DEPENDENT is a wak ntity typ.
Notation for ER Diagrams: Fig 3.4, 3.5 (Min,Max) notation ncapsulats both typs of structural constraints. This is mor gnral than prvious notation. Min >= implis TOTAL participation Min = 0 implis PARTIAL participation
Symbol Maning ENTITY TYPE WEAK ENTITY TYPE E R... E 2 RELATIONSHIP TYPE IDENTIFYING RELATIONSHIP TYPE ATTRIBUTE KEY ATTRIBUTE MULTIVALUED ATTRIBUTE COMPOSITE ATTRIBUTE DERIVED ATTRIBUTE TOTAL PARTICIPATION OF E 2 IN R Figur 3.4 Summary of ER diagram notation. E N R E 2 CARDINALITY RATIO : N FOR E :E 2 IN R R (MIN, MAX) E STRUCTURAL CONSTRAINT (min, max) ON PARTICIPATION OF E IN R
Figur 3.5 ER diagram for th COMPANY schma, with all rol nams includd and with structural constraints on rlationships spcifid using th altrnat notation (min, max). Fnam Minit Lnam Addrss Numbr Ssn Bdat Nam (0,N) Sx EMPLOYEE Salary (0,) (,) mploy (0,) managr (,N) workr StartDat WORKS_FOR MANAGES (4,N) dpartmnt NumbrOfEmploys Nam controllingdpartmnt (,) dpartmntmanagd DEPARTMENT Locations (0,N) suprvisor suprvis Hours CONTROLS SUPERVISION (0,N) mploy WORKS_ON projct (,N) controlldprojct (,) DEPENDENTS_OF Nam Numbr PROJECT Location dpndnt (,) DEPENDENT Nam Sx BirthDat Rlationship