Presentation is loading. Please wait.

Presentation is loading. Please wait.

ERD Exercises.

Similar presentations


Presentation on theme: "ERD Exercises."— Presentation transcript:

1 ERD Exercises

2 ERD Tips one AAA does many BBB one BBB is done by many AAA
a CCC has several BBB each BBB belongs to one CCC a, an, each  one  1 some, several  many  M 1 M CCC has BBB N does a DDD owns one AAA each AAA is owned by one DDD M 1 1 DDD owns AAA

3 ERD example A professor teaches many students.
A student is taught by several professors. M N PROFESSOR teaches STUDENT A professor teaches many classes. A class is taught by a single professor. 1 M N M PROFESSOR teaches CLASS enrolls ENROLL STUDENT 1 M M 1 A students enrolls in many classes. A class has many students. M N STUDENT enrolls ENROLL CLASS 1 M M 1

4 ERD Example Draw an E-R Diagram of the data model described by the business rules below. A professor can teach many classes. A class is taught by one professor. A student can take many classes. A class can have many students. A course can generate many classes. A class is generated by one course. 1 M M PROFESSOR teaches CLASS 1 ENROLL M 1 STUDENT M generates 1 COURSE

5 Data Modeling Exercises
Draw an E-R Diagram of the data model described by the business rules below. One region can be the location for many stores. Each store is located in only one region. Each store employs one or more employees. Each employee is employed by one store. A job can be assigned to many employees. -- e.g., The "Sales Representative" job can be assigned to more than one employee at a time. Each employee can have only one job assignment. Draw an E-R Diagram of the data model described by the business rules below. One region can be the location for many stores. Each store is located in only one region. Each store employs one or more employees. Each employee is employed by one store. A job can be assigned to many employees. -- e.g., The "Sales Representative" job can be assigned to more than one employee at a time. Each employee can have only one job assignment. Draw an E-R Diagram of the data model described by the business rules below. One region can be the location for many stores. Each store is located in only one region. Each store employs one or more employees. Each employee is employed by one store. A job can be assigned to many employees. -- e.g., The "Sales Representative" job can be assigned to more than one employee at a time. Each employee can have only one job assignment. REGION JOB 1 1 is location for is assigned to M M 1 M STORE employees EMPLOYEE Database Design

6 Data Modeling Exercises
Draw an E-R Diagram of the data model described by the business rules below. A sales rep can write many invoices. Each invoice is written by a single sales rep. A customer can generate many invoices. Each invoice is generated by a single customer. Each invoice includes one or more invoice lines. Each invoice line is associated with one invoice. - i.e., Each item purchased is recorded in an invoice line. Each invoice line records a single product. Each product can be recorded in many invoice lines. A customer can make many payments. Each payment is made by a single customer. A vendor supplies many products. A product is supplied by many vendors. Draw an E-R Diagram of the data model described by the business rules below. A sales rep can write many invoices. Each invoice is written by a single sales rep. A customer can generate many invoices. Each invoice is generated by a single customer. Each invoice includes one or more invoice lines. Each invoice line is associated with one invoice. - i.e., Each item purchased is recorded in an invoice line. Each invoice line records a single product. Each product can be recorded in many invoice lines. A customer can make many payments. Each payment is made by a single customer. A vendor supplies many products. A product is supplied by many vendors. M M 1 1 M INVOICE generates CUSTOMER makes PAYMENT 1 writes includes 1 M SALESREP INV_LINE M 1 1 M M 1 is in PRODUCT SUPPLY VENDOR Database Design

7 Data Modeling Exercises
Create an appropriate E-R diagram (with cardinalities) from the following business rules. A company division operates up to four departments. Each department employs employees. Each employee may have one or more dependents. Each employee may have an employment history. Each department has a manager. Create an appropriate E-R diagram (with cardinalities) from the following business rules. A company division operates up to four departments. Each department is operated by one division. Each department employs employees. An employ works for a single department. Each employee may have one or more dependents. A dependent must belong to an employee. Each employee may have an employment history. An employment history must be about an employee. Each department has a manager (is managed by an employee). An employ may manage a department. 1 M 1 DIVISION operates DEPARTMENT (1,4) (1,1) (1,1) 1 (1,N) employs manages M (1,1) (1,1) (0,N) (0,1) DEPENDENT claims EMPLOYEE M 1 1 1 (0,N) has M (1,1) EMP_HIST Database Design

8 Data Modeling Exercises
Identify the business rules and draw an E-R diagram of the situation described below. For each professor, there may be multiple advisees. A professor teaches many classes and a class is taught by one professor. Business Rules A professor can advise many students. A student is advised by one professor. A professor can teach many classes. A class is taught by one professor 1 M PROFESSOR teaches CLASS 1 advises M STUDENT Database Design

9 Database Design Exercises
Identify the business rules and draw an E-R diagram of the company described below. Yanghoo is a consulting company with multiple departments and many employees. Each department, run by a manager, has several employees who work on multiple projects. Business Rules A department employs many employees. Each employee works in one department. An employee may work on many projects. A project may have many employees working on it. A department is managed by one employee. An employee manages one department. DEPARTMENT 1 1 manages employs M 1 M N EMPLOYEE works on PROJECT Database Design

10 Database Design Exercises
Identify the business rules and draw an E-R diagram of the company described below. TeleFood Inc. sells food (e.g. cheese, cereals, beverages, etc.) products to customers.  TeleFood employees take orders over the phone, where a customer can order several products at one time.  The ordered product are shipped to the customers via UPS or FedEx.    TeleFood does not produce the products. Entities TeleFood, Food, Customer, Employee, Order, Product, UPS/FedEx  TeleFood, Food = Product, Customer, Employee, Order, UPS/FedEx = Shipper, (product) Vendor/Supplier Business Rules A customer can place many orders. Each order is placed by one customer. An employee can take many orders. Each order is taken by one employee. A shipper can ship many orders. Each order is shipped by one shipper. An order can include many products. A product can be included in many orders. A supplier can supply many products. Each product is supplied by one supplier. CUSTOMER 1 M SHIPPER ships ORDER OD_LINE PRODUCT 1 M M M 1 M 1 M supplies 1 1 EMPLOYEE SUPPLIER Database Design

11 Data Modeling Exercises
Sample DB Create a data model (i.e. ERD) for the school database described below. DB will keep track of advising and class information. DB should provide following information. - The list of students advised for a given year & dates of advising sessions for each students - Course listing for each year & student grades for each class Create a data model (i.e. ERD) for the school database described below. DB will keep track of advising and class information. DB should provide following information. - The list of students advised for a given year & dates of advising sessions for each students - Course listing for each year & student grades for each class Create a data model (i.e. ERD) for the school database described below. DB will keep track of advising and class information. DB should provide following information. - The list of students advised for a given year & dates of advising sessions for each students - Course listing for each year & student grades for each class Create a data model (i.e. ERD) for the school database described below. DB will keep track of advising and class information. DB should provide following information. - The list of students advised for a given year & dates of advising sessions for each students - Course listing for each year & student grades for each class Business Rules A professor can advise many students. A student is advised by one professor. A professor can teach many classes. A class is taught by one professor. A student can take many classes. A class can have many students. A course can generate many classes. A class is generated by one course. A professor can meet many times with an advisee. A student can meet many times with the advisor. 1 M PROFESSOR teaches CLASS 1 1 N M 1 M ADVISING advises generates takes ENROLL M M M M 1 M 1 1 STUDENT COURSE Database Design

12 Database Design Exercises
Below is an example of the CLASS entity implemented in MS Access. Do you see a problem? If so, how would you refine your data model? Sample DB There is a data redundancy problem (e.g., Class Name, Code, etc.) → Can lead to data anomalies (i.e., Update/Insertion/Deletion Anomaly) M N 1 M PROFESSOR teaches COURSE has CLASS N takes ERD Refinement #1 Separate the course information into a COURSE entity. A professor can teach many courses. A course can be taught by many professors A course can consist of many classes. A class belongs to one course A student can enroll in many classes. Each class can have many students. Sample DB M STUDENT Database Design

13 Database Design Exercises
Below is an example of the CLASS entity implemented in MS Access. Do you see a problem? If so, how would you refine your data model? ERD Refinement #2 Decompose many-to-many relationship Sample DB M N 1 M PROFESSOR TEACH teaches COURSE has CLASS 1 M M 1 1 N M ENROLL takes M M 1 STUDENT Database Design

14 Database Design Exercises
The E-R diagram below, which models the course enrollment in a college, has a serious flaw. What is the problem and how can it be fixed? Show a revised E-R diagram. 1 M M 1 1 M PROFESSOR TEACH teaches COURSE has CLASS 1 ERD misses the relationship between PROFESSOR and CLASS → does not record who taught the specific classes M ENROLL takes M ERD Refinement #3 Relate PROFESSOR to CLASS Sample DB 1 STUDENT 1 M M 1 COURSE has CLASS teach PROFESSOR 1 M ENROLL M 1 STUDENT Database Design

15 Database Design: University Database
Construct a data model of a typical university. To keep track of class & advising information by department (double-major allowed) Database Objectives Generate a course listing by semester (e.g., professor, department, class time & place) For each professor, generate the classes taught & student grades for each class. For each student, generate the complete listing of advising sessions (e.g, date, time, advisor) For each school, generate a list of all employees by department. For each department, generate a listing of all double-major students. Database Objectives Generate a course listing by semester (e.g., professor, department, class time & place) For each professor, generate the classes taught & student grades for each class. For each student, generate the complete listing of advising sessions (e.g, date, time, advisor) For each school, generate a list of all employees by department. For each department, generate a listing of all double-major students. Business Rules A school can have many departments. Each department belongs to one school. A department has many employees. An employee works in one departments. An employee can be a professor or a staff. A course generates many classes. Each class belongs to a course. A professor teaches many classes. A class is taught by one professor. A student can take many classes. A class has many students. A student belongs to one department. A department has many students. A student can double-major in a department. A department can have many double-major students. Database Design

16 Database Design: University Database
Construct a data model of a typical university. To keep track of class & advising information by department (double-major allowed) Business Rules A school can have many departments. Each department belongs to one school. A department has many employees. An employee works in one departments. An employee can be a professor or a staff. A course generates many classes. Each class belongs to a course. A professor teaches many classes. A class is taught by one professor. A student can take many classes. A class has many students. A student belongs to one department. A department has many students. A student can double-major in a department. A department can have many double-major students. Business Rules A school can have many departments. Each department belongs to one school. A department has many employees. An employee works in one departments. An employee can be a professor or a staff. A course generates many classes. Each class belongs to a course. A professor teaches many classes. A class is taught by one professor A student can take many classes. A class has many students. A student belongs to one department. A department has many students. A student can double-major in a department. A department can have many double-major students. M 1 M DEPARTMENT has STUDENT 1 1 M 1 major2 M has ENROLL has M 1 M 1 SCHOOL EMPLOYEE 1 1 1 M M 1 is PROFESSOR CLASS COURSE Database Design

17 Database Design: University Database
Convert the data model of a university to a relational schema. Sample DB Database Design

18 Database Design: University Database
One of the database objective is to generate a list of students advised for a given year & dates of advising sessions for each students for each professor. Modify the ERD to support this DB objective. Business Rules A professor can meet many times with an advisee. A student can meet many times with a professor Sample DB M 1 M DEPARTMENT has STUDENT 1 M 1 1 1 major2 M M has has ENROLL ADVISING M M 1 M 1 1 1 1 1 M M 1 SCHOOL EMPLOYEE is PROFESSOR CLASS COURSE Database Design

19 Database Design: University Database
Data model below corrects the following problems with the previous data model. The departmental advisor information is missing -- A student may consult with a professor who is not his/her departmental advisor A professor can advise many students. A student is advised by one professor. The department designation for courses is missing -- A professor may teach courses outside of his/her department. A department offers many courses. A course is offered by one department. Sample DB 1 offers M 1 M DEPARTMENT has STUDENT 1 M 1 1 1 major2 M M M has has ENROLL advises ADVISING M M 1 M 1 M 1 1 1 1 1 M M 1 SCHOOL EMPLOYEE is PROFESSOR CLASS COURSE Database Design


Download ppt "ERD Exercises."

Similar presentations


Ads by Google