6.8 Case Study: E-R for Supplier-and-Parts Database Unit 6 Database Design and the E-R Model 6-1 Supplier-and-Parts Database Supplier-and-Parts Database <e.g.> Supplier-and-Parts Database S P S# SNAME STATUS CITY S1 Smith 20 London S2 Jones 10 Paris S3 Blake 30 Paris S4 Clark 20 London S5 Adams 30 Athens P# PNAME P1 Nut P2 Bolt P3 Screw P4 Screw P5 Cam P6 Cog Wei-Pang Yang, Information Management, NDHU COLOR Red Green Blue Red Blue Red WEIGHT CITY 12 London 17 Paris 17 Rome 14 London 12 Paris 19 London SP S# P# QTY S1 P1 300 S1 P2 200 S1 P3 400 S1 P4 200 S1 P5 100 S1 P6 100 S2 P1 300 S2 P2 400 S3 P2 200 S4 P2 200 S4 P4 300 S4 P5 400 Unit 6 Database Design and the E-R Model 6-2 Entity/Relationship Diagram Regular Entity <e.g> Weak Entity ... Department Dependent 1 Property: Base ... First Department_Emp Derived M Emp_Dependent Ename M Multi 1 Employee Emp# Key Last MI Composite Salary ... Entity : M 1 Proj_Work Proj_Mngr Relationship: M M Project P# Regular Weak total partial ... Part Exp M M Imp S# Qty M M SPJ M M Sname Supplier Status City SP Part_Struct Qty Qty Wei-Pang Yang, Information Management, NDHU Unit 6 Database Design and the E-R Model 6-3 Semantic Concepts Entity: a thing which can be distinctly identified. e.g. S, P • Weak Entities: an entity that is existence-dependent on some other entity. e.g. Dependent • Regular Entities: an entity that is not weak. Property: • Simple or Composite Property • key: unique value • Single or Multi-valued: i.e. repeating data • Missing: unknown or not applicable. • Base or Derived: e.g. "total quantity" Wei-Pang Yang, Information Management, NDHU Unit 6 Database Design and the E-R Model 6-4 Semantic Concepts (cont.) Relationship: association among entities. • participant: the entity participates Dependent M in a relationship. e.g. Employee, Dependent 1 • degree of relationship: number of participants. • total participant: every instance is used. e.g. Dependent • partial participant: e.g. Employee Employee Employee E1 E2 E3 E4 . . . . Dependent . . . . Note: An E/R relationship can be one-to-one, one-tomany, many-to-one, or many-to-many. Wei-Pang Yang, Information Management, NDHU Unit 6 Database Design and the E-R Model 6-5 Semantic Concepts (cont.) Subtype: Any given entity can be a subtype of other entity. e.g. An example type hierarchy: Employee Programmer Application Programmer System Programmer • Programmer Employee • Application Programmer Programmer Wei-Pang Yang, Information Management, NDHU Unit 6 Database Design and the E-R Model 6-6 Transfer E-R Diagram to SQL Definition ER-Diagram (1) Regular Entities Base Relations e.g. Department DEPT Employee EMP Supplier S Part P Project J attributes: properties. primary key: key property. <e.g> CREATE TABLE EMP SQL Definition (EMP# ...... .. . primary key (EMP#)); .. . (2) Properties attributes multivalued property: normalized first. Wei-Pang Yang, Information Management, NDHU Unit 6 Database Design and the E-R Model 6-7 Transfer E-R Diagram to SQL Definition (cont.) (3) Many-to-Many Relationships Base Relations P# S# M P <e.g.> Consider SUPP-PART SP <e.g.> CREATE – primary key: (1) combination of foreign keys, or (2) introduce a new attribute. ID 1 2 3 ... Wei-Pang Yang, Information Management, NDHU M S QTY – foreign keys: key attributes of the participant entity. – attributes: primary key foreign keys properties SP S# P# QTY TABLE SP ( S#, ..., P#, ..., Qty, ..., FOREIGN KEY (S#) REFERENCES S NULL NOT ALLOWED DELETE OF S RESTRICTED UPDATE OF S.S# CASCADES FOREIGN KEY (P#) REFERENCES P ...... PRIMARY KEY (S#, P#) ) Unit 6 Database Design and the E-R Model 6-8 Transfer E-R Diagram to SQL Definition (cont.) (4) Many-to-One or One-to-Many or One-to-One Relationships → 不用給Base-Relation, 但…. DEPT# e.g. Consider DEPT_EMP(Department_Employee) DEPT_EMP 1° no any new relation is necessary. 2° Introduce a foreign key in "many" side relation (eg. EMP) that reference the "one" side relation (eg. DEPT). Department (DEPT) 1 M EMP# Employee (EMP) DEPT# CREATE TABLE EMP ( EMP#, ... DEPT#, ... ...... FOREIGN KEY (DEPT#) REFERENCES DEPT ...... ); Wei-Pang Yang, Information Management, NDHU Unit 6 Database Design and the E-R Model 6-9 Transfer E-R Diagram to SQL Definition (cont.) (5) Weak Entities Base Relation + Foreign Key • foreign key: key property of its dependent entity e.g. EMP# • primary key: e.g. name name (1) combination of foreign key and its own primary key EMP# (2) introduce a new attribute e.g. CREATE TABLE DEPENDENT Dependent M ( EMP#, … 1 name, EMP ...... EMP# FOREIGN KEY (EMP#) REFERENCES EMP NULL NOT ALLOWED DELETE OF EMP CASCADES UPDATE OF EMP.EMP# CASCADES PRIMARY KEY ( EMP#, DEPENDENT_NAME ) ); Wei-Pang Yang, Information Management, NDHU Unit 6 Database Design and the E-R Model 6-10 Transfer E-R Diagram to SQL Definition (cont.) (6) Supertypes and SubtypesBase Relation + Foreign Key <e.g.> CREATE TABLE EMP ( EMP#, ... DEPT#, ... SALARY, ... ...... PRIMARY KEY (EMP#), ...); EMP PGMR CREATE TABLE PGMR ( EMP#, ... LANG#, ... SALARY, ... ...... PRIMARY KEY (EMP#) FOREIGN KEY (EMP#) REFERENCES EMP ......); Wei-Pang Yang, Information Management, NDHU Unit 6 Database Design and the E-R Model 6-11 17.7 The Entity/Relationship Model Proposed by Peter Pin-Shan Chen. “The Entity- Relationship Model,” in ACM Trans. on Database System Vol. 1, No. 1, pp.9-36, 1976. E-R Model contains: • Semantic Concepts and • E/R Diagram. 17-12 Entity/Relationship Diagram Regular Entity <e.g> Weak Entity ... Department Dependent 1 Property: Base ... First Department_Emp Derived M Emp_Dependent Ename M Multi 1 Employee Emp# Key Last MI Composite Salary ... Entity : M 1 Proj_Work Proj_Mngr Relationship: M M Project Regular Weak total partial P# ... Part Exp M M Imp S# Qty M M SPJ M M Sname Supplier Status City SP Part_Struct Qty Qty Wei-Pang Yang, Information Management, NDHU 17-13 Semantic Concepts Entity: a thing which can be distinctly identified. e.g. S, P • Weak Entities: an entity that is existence-dependent on some other entity. e.g. Dependent • Regular Entities: an entity that is not weak. Property: • Simple or Composite Property • key: unique value • Single or Multi-valued: i.e. repeating data • Missing: unknown or not applicable. • Base or Derived: e.g. "total quantity" Wei-Pang Yang, Information Management, NDHU 17-14 Semantic Concepts (cont.) Relationship: association among entities. • participant: the entity participates Dependent M in a relationship. e.g. Employee, Dependent 1 • degree of relationship: number of participants. • total participant: every instance is used. e.g. Dependent • partial participant: e.g. Employee Employee Employee E1 E2 E3 E4 . . . . Dependent . . . . Note: An E/R relationship can be one-to-one, one-tomany, many-to-one, or many-to-many. Wei-Pang Yang, Information Management, NDHU 17-15 Semantic Concepts (cont.) Subtype: Any given entity can be a subtype of other entity. e.g. An example type hierarchy: Employee Programmer Application Programmer System Programmer • Programmer Employee • Application Programmer Programmer Wei-Pang Yang, Information Management, NDHU 17-16 Transfer E-R Diagram to SQL Definition ER-Diagram (1) Regular Entities Base Relations e.g. Department DEPT Employee EMP Supplier S Part P Project J attributes: properties. primary key: key property. <e.g> CREATE TABLE EMP SQL Definition (EMP# ...... .. . primary key (EMP#)); .. . (2) Properties attributes multivalued property: normalized first. Wei-Pang Yang, Information Management, NDHU 17-17 Transfer E-R Diagram to SQL Definition (cont.) (3) Many-to-Many Relationships Base Relations P# S# M P <e.g.> Consider SUPP-PART SP <e.g.> CREATE – primary key: (1) combination of foreign keys, or (2) introduce a new attribute. ID 1 2 3 ... Wei-Pang Yang, Information Management, NDHU M S QTY – foreign keys: key attributes of the participant entity. – attributes: primary key foreign keys properties SP S# P# QTY TABLE SP ( S#, ..., P#, ..., Qty, ..., FOREIGN KEY (S#) REFERENCES S NULL NOT ALLOWED DELETE OF S RESTRICTED UPDATE OF S.S# CASCADES FOREIGN KEY (P#) REFERENCES P ...... PRIMARY KEY (S#, P#) ) 17-18 Transfer E-R Diagram to SQL Definition (cont.) (4) Many-to-One or One-to-Many or One-to-One Relationships → 不用給Base-Relation, 但…. DEPT# e.g. Consider DEPT_EMP(Department_Employee) DEPT_EMP 1° no any new relation is necessary. 2° Introduce a foreign key in "many" side relation (eg. EMP) that reference the "one" side relation (eg. DEPT). Department (DEPT) 1 M EMP# Employee (EMP) DEPT# CREATE TABLE EMP ( EMP#, ... DEPT#, ... ...... FOREIGN KEY (DEPT#) REFERENCES DEPT ...... ); Wei-Pang Yang, Information Management, NDHU 17-19 Transfer E-R Diagram to SQL Definition (cont.) (5) Weak Entities Base Relation + Foreign Key • foreign key: key property of its dependent entity • primary key: e.g. EMP# e.g. name name (1) combination of foreign key and its own primary key (2) introduce a new attribute EMP# Dependent e.g. CREATE TABLE DEPENDENT M ( EMP#, … name, 1 ...... EMP EMP# FOREIGN KEY (EMP#) REFERENCES EMP NULL NOT ALLOWED DELETE OF EMP CASCADES UPDATE OF EMP.EMP# CASCADES PRIMARY KEY ( EMP#, DEPENDENT_NAME ) ); Wei-Pang Yang, Information Management, NDHU 17-20 Transfer E-R Diagram to SQL Definition (cont.) (6) Supertypes and SubtypesBase Relation + Foreign Key <e.g.> CREATE TABLE EMP ( EMP#, ... DEPT#, ... SALARY, ... ...... PRIMARY KEY (EMP#), ...); EMP PGMR CREATE TABLE PGMR ( EMP#, ... LANG#, ... SALARY, ... ...... PRIMARY KEY (EMP#) FOREIGN KEY (EMP#) REFERENCES EMP ......); Wei-Pang Yang, Information Management, NDHU 17-21 Home Work: Term Project Design and implementation an useful, complete, and “real” database system. Steps: Take any data you are familiar with. (from your work or ?) System Analysis represented by flow chart By using the E-R model to analysis and describe your data. Design logical database, user interface, and more Design the database system as “complete and real” as possible. Due: Demo and A Comprehensive Report Wei-Pang Yang, Information Management, NDHU 17-22 end of unit 17 Wei-Pang Yang, Information Management, NDHU
© Copyright 2026 Paperzz