








Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!









Second Normal Form (2NF) BAGEL ORDER BAGEL ORDER LINE ITEM BAGEL PK Bagel Order ID PK / FK Bagel Order ID PK Bagel ID Order Date 1:M PK / FK Bagel ID M:1 Bagel Name First Name Bagel Quantity Bagel Description Last Name Bagel Price Address 1 Address 2 City State Zip Mobile Phone Delivery Fee Special Notes
I started by splitting the 1 NF table into three tables: Bagel Order, Bagel Order Line Item, and Bagel tables. This was done to ensure that each attribute is fully functionally dependent on the primary key of each table. As a good rule of thumb, each table should relate to only one theme, so splitting the 1NF table into the three themes of Bagel Order, Bagel Order Line Item and the Bagel tables ensures that the attributes assigned to each of the table is fully functionally dependent on the primary key of each table. The Bagel Order table has Bagel Order ID as its primary key, while the Bagel table has Bagel ID as its primary key. The Bagel Order Line Item table is used as an associative table to associate the Bagel Order and Bagel tables together. It has Bagel Order ID and Bagel ID as its composite primary
key. The Bagel Order ID acts as a foreign key in the Bagel Order Line Item table to relate the table to the Bagel Order table. It also has Bagel ID as a foreign key to relate it to the Bagel table. The Bagel Order and Bagel Order Line Item tables have a cardinality of one-to-many. This means that a bagel order can have many line items, but a line item can be part of only one Bagel order. The Bagel Order Line Item and Bagel tables have a cardinality of many-to-one. This means that a maximum of one bagel can be part of a bagel order, but that a single bagel can be part of many bagel orders.
Third Normal Form (3NF) BAGEL ORDER BAGEL ORDER LINE ITEM BAGEL PK Bagel Order ID PK / FK Bagel Order ID PK Bagel ID FK Customer ID 1:M PK / FK Bagel ID M:1 Bagel Name Order Date Bagel Quantity Bagel Description Delivery Fee Bagel Price Special Notes M: CUSTOMER PK Customer ID First Name Last Name Address 1 Address 2 City State Zip Mobile Phone
Final Physical Database Model BAGEL ORDER BAGEL ORDER LINE ITEM BAGEL PK BagelOrderId INTEGER PK / FK BagelOrderId INTEGER PK BagelId CHAR( 2 ) FK CustomerId INTEGER 1:M PK / FK BagelId CHAR(2) M:1 BagelName VARCHAR( 25 ) OrderDate TIMESTAMP Bagel Quantity INTEGER BagelDescription VARCHAR( 50 ) DeliveryFee NUMERIC(4,2) BagelPrice NUMERIC(3,2) SpecialNotes VARCHAR( 50 ) M: CUSTOMER PK CustomerId INT FirstName VARCHAR( 20 ) LastName VARCHAR( 20 ) Address1 VARCHAR( 50 ) Address2 VARCHAR( 50 ) City VARCHAR( 20 ) State VARCHAR( 20 ) Zip VARCHAR( 10 ) MobilePhone VARCHAR( 15 )
shop_id INTEGER, shop_name VARCHAR( 50 ), city VARCHAR( 50 ), state CHAR( 2 ), PRIMARY KEY(shop_id) ); CREATE TABLE EMPLOYEE( employee_id INTEGER, first_name VARCHAR( 30 ), last_name VARCHAR( 30 ), hire_date DATE, job_title VARCHAR( 30 ), shop_id INTEGER, PRIMARY KEY(employee_id), FOREIGN KEY(shop_id) REFERENCES COFFEE_SHOP(shop_id) );
CREATE VIEW EMPLOYEE_DESC AS SELECT employee_id, CONCAT(first_name,' ', last_name) AS employee_full_name, hire_date, job_title, shop_id FROM EMPLOYEE;
FROM EMPLOYEE AS e JOIN COFFEE_SHOP AS cs ON e.shop_id = cs.shop_id JOIN COFFEE AS c ON cs.shop_id = c.shop_id;