Homework #1 Please upload to Canvas any time before but not later than Sunday, Feb. 16 Homework is accepted only through the Homework link in Canvas Late homework is not accepted Prepare an entity-relationship (ER) diagram using MySQL Workbench for the business case described below. Your ER diagram should have entities and also relationships between entities. Every entity in the diagram should have primary key. Also, entities should have foreign key columns where necessary, along with other columns as described in the business requirements listed below. Include a text box in the diagram in which you should write your full name, and BUS 112 Section (1 or 2). Save completed diagram on your computer (from the menu, select File > Save Model As...) and name the file as your last name. Upload the your-last-name.mwb file to Canvas. Business Case & Requirements Pacific Trading is a wholesale business organization that sells a variety of products to its retail business customers (which include retailers such as Target, Wal-Mart, etc.) Pacific Trading has asked you to design a small database with the following business rules and requirements: • When a Pacific Trading customer purchases products, an invoice is prepared for the customer. A single invoice can list one or more products that the customer has purchased including product information such as price per unit and quantity sold. • A Pacific Trading customer may receive one or more invoices, though each invoice is associated with a single customer. Besides the necessary primary and foreign key columns, please be sure that the following attributes are also included in your ER diagram: Product name; customer name; customer phone number; customer credit limit; date of invoice; information about products being invoiced including product code, quantity sold (i.e., how many units of the product the customer bought), and product price per unit. The Relational Data Model Chapter 3 © 2019 Cengage. May not be copied, scanned, or duplicated, in whole or in part, except for use as permitted in a license distributed with a certain product or service or otherwise on a passwordprotected website for classroom use. A Simple Relational Model Example Conceptual and Internal (Logical) Models A Simple Relational Database Example Containing Only Two Tables Basic Terminology • Table: a structure with rows and columns that contains a unique set of one or more records. Also called: entity, relation, file • Column: Also called a filed, and attribute • Record: Also called a row, and tuple • Cell: Intersection of a row and a column; holds no more than one data item 6 Data Values Primary Key • Each row in a table must be uniquely identifiable • A Primary Key is one or more attributes (columns) that uniquely identify a record, i.e., data in each column of the record is uniquely identifiable by the PK. The Primary Key Concept is Associated with the Concept of Functional Dependence Functional Dependence: A→B (A determines B) A→B (B is functionally dependent on A) You can read the above functional association as this: If you know the value of attribute A, you can uniquely determine the value of attribute B Examples of Functional Dependence Student ID → First Name, Last Name Course# → Course Title None of the functional dependence listed in blue font is valid, whereas all those in green font are valid An Example of Database Schema (Table Structure) INSTRUCTOR (Instructor_ID, First_Name, Last_Name, Phone) Primary Key CLASS (Class_Code, Class_Title, Instructor_ID) Foreign Key ENROLLMENT(C Grade) STUDENT(Student_ID, Last_Name, SS#) Composite Primary Key Candidate Key Composite Primary Key; Surrogate Key • A primary key that is composed of more than one attribute, like the following in the GRADES table: Composite Primary Key ENROLLMENT (Student-ID, Class-Code, Grade) ENROLLMENT (Enrollment_ID, Student-ID, Class-Code, Grade) Surrogate Key (Replaces a composite key) Foreign Key • Foreign key (FK) An attribute or column in one table that references the primary key column of another table • Referential integrity If referential integrity is enforced then every data value in the FK column must match an existing data value in the related PK column of the parent table Foreign Key Example Foreign Key Example Practice: Do these tables satisfy the referential integrity constraint? NOTES: (1) One salesperson may sell many products but a product is sold by one salesperson at a time. (2) Assume the database currently has the data that is visible in this slide. Practice: Do these tables satisfy the referential integrity constraint? NOTES: (1) One salesperson may sell many products but a product is sold by one salesperson at a time. (2) Assume the database currently has the data that is visible in this slide. Practice: Do these tables satisfy the referential integrity constraint? NOTES: (1) One salesperson may sell many products but a product is sold by one salesperson at a time. (2) Assume the database currently has the data that is visible in this slide. MySQL Default: ON DELETE NO ACTION Other DBMS: ON DELETE RESTRICT Entity Integrity; Referential Integrity Null Values • No data entry in a cell • Nulls are not permitted in primary key column