Vous êtes sur la page 1sur 4

ERD IN CLASS EXAMPLES Business rules (i.e., relationships) Example 1 1.

a professor teaches zero, one or many classes and a class is taught by one professor 2. a course may generate zero, one or many classes and a class comes from one course 3. a class is held in one room but a room has many classes Example 2 (try this at home and if you have questions raise them next class) 1. an invoice is written by one salesrep but a salesrep writes many invoices 2. a vendor sells many products but a product is bought from one vendor 3. an invoice has one or many products and a product is found on zero, one or many invoices

Example-1 Solution (Incomplete) The many-to-many relationship is not resolved, therefore the solution is incomplete. In the final solution the many-to-many must always be resolved.
STUDENT PK STUD_ID STUD_FNAME STUD_LNAME STUD_STREET STUD_CITY STUD_ZIP

CLASS PROFESSOR PK PROF_ID


teaches

ROOM PK ROOM_ID ROOM_LOC ROOM_CAP CLASS_ID

PK

CLASS_ID CLASS_NAME PROF_ID CLASS_ID COURSE_ID

PROF_LNAME PROF_FNAME

generates

COURSE PK COURSE_ID COURSE_NAME

Final Solution (Complete) In this example, the many-to-many relationship between student and class is resolved.

STUDENT PK Stud_ID STUD_FNAME STUD_LNAME STUD_STREET STUD_CITY PK PK ENROLL STUD_ID CLASS_ID GRADE

ROOM PROF PK PROF_ID


teaches

CLASS PK CLASS_ID CLASS_NAME PROF_ID

PK

ROOM_ID ROOM_LOC ROOM_CAP CLASS_ID

PROF_LNAME PROF_FNAME

generates

COURSE PK COURSE_ID COURSE_NAME CLASS_ID

Solution to the INVOICE problem


INVOICE PK INV_# INV_DATE CUST_LNAME CUST_FNAME CUST_STREET CUST_CITY PK PK INV_LINE_ITEM INV_# PROD_ID PROD_QUANTITY

SALESREP PK SALESREP_ID SALESREP_LNAME SALESREP_FNAME SALESREP_TEL


SELLS

PRODUCT PK PROD_ID PROD_NAME SALESREP_ID VEND_ID

SELLS

VENDOR PK VEND_ID VEND_NAME VEND_STREET VEND_CITY VEND_ZIP VEND_TEL

Vous aimerez peut-être aussi