Docsity

Data Management Applications c170, Assignments of Advanced Data Analysis

Partial preview of the text

Download Data Management Applications c170 and more Assignments Advanced Data Analysis in PDF only on Docsity!

Data Management – Applications – C

Performance Assessment

Sarah De Roest

Nora’s Bagel Bin Database Blueprints

First Normal Form (1NF) BAGEL ORDER PK Bagel Order ID PK Bagel ID Order Date First Name Last Name Address 1 Address 2 City State Zip Mobile Phone Delivery Fee Bagel Name Bagel Description Bagel Price Bagel Quantity Special Notes

Section A

Nora’s Bagel Bin Database Blueprints (continued)

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: CUSTOMERS BAGEL PK Customer ID First Name Last Name Address 1 Address 2 City State Zip Mobile Number To move further into third normal form, I needed to look at the tables to make sure any of them could be broken down even more. Looking at the Bagel order table in second normal form, I notice that this table could be broken down further. I extracted all the attributes that had to do with customers information. I called the table “Costumers” and assigned Customer ID as the primary key, which would be the foreign key in the Bagel Order table. All the costumer information can be put into one table now. This is very helpful because now this information can be reused if the customer orders more bagels in the future and the costumer info is already saved in the bagel shops computer. The cardinality between bagel order and the new customer table will become many-to-one after its broken into two tables, because there can be many orders per customer but there cannot be many customers per order. The other two tables will keep all its same attributes listed and its cardinalities between each other.

Section A

Nora’s Bagel Bin Database Blueprints (continued)

Final Physical Database Model BEGAL ORDER BAGEL ORDER LINE ITEM BAGEL PK Bagel Order ID INT PK / FK bagel_order_id INT PK Bagel ID CHAR (2) FK Customer ID INT 1:M PK / FK bagel_id CHAR(2) M:1 Bagel Name VARCHAR(20) Order Date TIMESTAMP Bagel quantity INT Bagel Description VARCHAR(50) Delivery fee NUM (2,2) Bagel Price NUM(2,2) Special Notes VARCHAR (50) M: CUSTOMERS PK Customer ID INT First Name VARCHAR(20) Last Name VARCHAR(20) Address 1 VARCHAR(20) Address 2 VARCHAR(10) City VARCHAR(20) State CHAR(2) Zip CHAR(10) Mobile Number CHAR(10)

CREATE TABLE Coffee_Shop

Shop_ID INT,

Shop_Name VARCHAR (50),

City VARCHAR (50),

STATE CHAR (2),

PRIMARY KEY (Shop_ID)

SELECT * FROM Coffee_shop;

CREATE TABLE Coffee

Coffee_ID INT,

Shop_ID INT,

Supplier_ID INT,

Coffee_Name VARCHAR (30),

Price_Per_Pound NUMERIC (5,2),

PRIMARY KEY (Coffee_ID),

FOREIGN KEY (Shop_ID) REFERENCES

COFFEE_SHOP(Shop_ID)

SELECT * FROM Coffee;

ALTER TABLE Employee

ADD FOREIGN KEY (Shop_ID)

REFERENCE COFFEE_SHOP (Shop_ID)

ALTER TABLE Coffee

ADD FOREIGN KEY (Supplier_ID)

REFERENCES SUPPLIER (Supplier_ID)

Section B

INSERT INTO coffee_shop (Shop_id, Shop_name, City, State)

VALUES ('1', 'ABC Beans', 'Seattle', 'Wa')

INSERT INTO coffee_shop (Shop_id, Shop_name, City, State)

VALUES ('2', 'Space Bar Cyber Cafe', 'Los Angeles', 'Ca');

INSERT INTO Coffee_shop (Shop_id, Shop_name, City,

State)

VALUES ('3', 'Coffee Town Beanery', 'New York', "Ny")

INSERT INTO Supplier (supplier_id, company_name, country,

sales_contact_name, email)

VALUES ('1', 'Silvias Java Emporium', 'USA', 'Steven Williams',

'[email protected]')

INSERT INTO Supplier (supplier_id,

company_name, country,

sales_contact_name, email)

VALUES ('2', 'Steamers Coffee Supply

Company', 'USA', 'Linda MacDonald',

'[email protected]')

INSERT INTO Supplier (supplier_id,

company_name, country,

sales_contact_name, email)

VALUES ('3', 'Coffee and More Inc',

'USA', 'Lee Smith',

'[email protected]');

INSERT INTO Coffee (Coffee_id,

Shop_id, Supplier_id, Coffee_name,

Price_per_pound)

VALUES ('1', '1', '1', 'Arabica Rich Dark

Roast', '9.99')

INSERT INTO Coffee (Coffee_id,

Shop_id, Supplier_id, Coffee_name,

Price_per_pound)

VALUES ('2', '2', '2', 'Tall Blonde

Roast', '8.99')

INSERT INTO Coffee (Coffee_id,

Shop_id, Supplier_id, Coffee_name,

Price_per_pound)

VALUES ('3', '3', '3', 'American

Breakfast Roast', '5.99');

SELECT * FROM coffee;

SELECT * FROM Employee;

Section B

CREATE VIEW employee_view

AS SELECT employee_id,

CONCAT(first_name,' ', last_name) AS

employee_full_name, hire_date, job_title,

shop_id

FROM Employee

SELECT * FROM employee_view;