Docsity

Data Management – Applications C170 VHT2 Task 1: NORMALIZATION AND DATABASE DESIGN Latest., Exams of Nursing

Toggle sidebar
bg1
Data Management – Applications C170
VHT2 Task 1: NORMALIZATION AND DATABASE DESIGN
Latest.
construct a normalized physical database model to represent the ordering process for Nora’s Bagel Bin
by doing the following:
A-1 Complete the second normal form (2NF) section of the attached “Nora’s Bagel Bin Database
Blueprints” document by doing the following:
a. Assign each attribute from the 1NF table into the correct 2NF table.
b. Describe the relationship between the two pairs of 2NF tables by indicating their
cardinality in each of the dotted cells: one-to-one (1:1), one-to-many (1:M), many-to-one (M:1),
or many-to-many (M:M).
c. Explain how you assigned attributes to the 2NF tables and determined the cardinality
of the relationships between your 2NF tables.
To assign attributes to the 2NF tables three tables were created; “Bagel Order”, “Bagel Order Line Item”
and “Bagel”. This will support aligning all of the non-attribute keys to their respective primary key; “Bagel
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe

Partial preview of the text

Download Data Management – Applications C170 VHT2 Task 1: NORMALIZATION AND DATABASE DESIGN Latest. and more Exams Nursing in PDF only on Docsity!

Data Management – Applications C

VHT2 Task 1: NORMALIZATION AND DATABASE DESIGN

Latest.

c onstruct a normalized physical database model to represent the ordering process for Nora’s Bagel Bin by doing the following: A-1 Complete the second normal form (2NF) section of the attached “Nora’s Bagel Bin Database Blueprints” document by doing the following:

a. Assign each attribute from the 1NF table into the correct 2NF table.

b. Describe the relationship between the two pairs of 2NF tables by indicating their

cardinality in each of the dotted cells: one-to-one (1:1), one-to-many (1:M), many-to-one (M:1), or many-to-many (M:M).

c. Explain how you assigned attributes to the 2NF tables and determined the cardinality

of the relationships between your 2NF tables. To assign attributes to the 2NF tables three tables were created; “Bagel Order”, “Bagel Order Line Item” and “Bagel”. This will support aligning all of the non-attribute keys to their respective primary key; “Bagel

Order ID” is the primary key for the “Bagel Order” table, “Bagel ID’ is the primary key for the “Bagel” table and the table “Bagel Order Line Item” intersects both tables by having both primary keys and associating them. The relationship between the “Bagel Order” and “Bagel Order Line Item” tables from left to right is many-to-one. While being read right to left, the association is one to many. Because many “Bagel Order Line Item” can be placed in one “Bagel Order”, and a “Bagel Order” must contain at least, but not limited to one “Bagel Order Line Item”. The cardinality when read is a many to one because of the relationship between the two tables. The relationship between the “Bagel” and the “Bagel Order Line Item” tables from left to right is many-to-one and read from right to left is one-to-many, because one “Bagel” can be a line item in multiple orders, but the “Bagel Order Line Item” could contain one or more “Bagel”. Reading the cardinality from left to right is one-to-many. A-2 Complete the third normal form (3NF) section of the attached “Nora’s Bagel Bin Database Blueprints” document by doing the following: a. Assign each attribute from your 2NF "Bagel Order" table into one of the new 3NF tables. Copy all other information from your 2NF diagram into the 3NF diagram. b. Provide each 3NF table with a name that reflects its contents.

c. Create a new field that will be used as a key linking the two 3NF tables you named in part A2b.

Ensure that your primary key (PK) and foreign key (FK) fields are in the correct locations in the 3NF diagram.

d. Describe the relationships between the 3NF tables by indicating their cardinality in each of the

dotted cells: one-to-one (1:1), one-to-many (1:M), many-to-one (M:1), or many-to-many (M:M). To obtain the third normal form (3NF) the tables must not have transitive dependencies; meaning non- key attributed can’t depend on an attribute that isn’t the primary key. To turn the tables from a 2NF to

B. Create a database using the attached “Jaunty Coffee Co. ERD” by doing the following:

B-1 Develop SQL code to create each table as specified in the attached: “Jaunty Coffee Co. ERD” by doing the following: a. Provide the SQL code you wrote to create all tables. CREATE TABLE EMPLOYEE ( employee_id INT, first_name VARCHAR(30), last_name VARCHAR(30), hire_date DATE, job_title VARCHAR(30), shop_id INT, PRIMARY KEY (employee_id) ); CREATE TABLE COFFEE_SHOP ( shop_id INT, shop_name VARCHAR(50), city VARCHAR(50), state1 CHAR(2), PRIMARY KEY (shop_id) ); ALTER TABLE EMPLOYEE ADD FOREIGN KEY (shop_id) REFERENCES COFFEE_SHOP(shop_id); 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) ); CREATE TABLE SUPPLIER ( supplier_id INT, company_name VARCHAR(50), country VARCHAR(30), sales_contact_name VARCHAR(60), email VARCHAR(50) NOT NULL, PRIMARY KEY (supplier_id) ); ALTER TABLE COFFEE ADD FOREIGN KEY (supplier_id) REFERENCES SUPPLIER(supplier_id); b. Demonstrate that you tested your code by providing a screenshot showing your SQL commands and the database server’s response.

B-2 Develop SQL code to populate each table in the database design document by doing the following: a. Provide the SQL code you wrote to populate the tables with at least three rows of data in each table. CREATE TABLE EMPLOYEE ( employee_id INT, first_name VARCHAR(30), last_name VARCHAR(30), hire_date DATE, job_title VARCHAR(30), shop_id INT, PRIMARY KEY (employee_id) ); CREATE TABLE COFFEE_SHOP ( shop_id INT, shop_name VARCHAR(50), city VARCHAR(50), state1 CHAR(2), PRIMARY KEY (shop_id) ); ALTER TABLE EMPLOYEE ADD FOREIGN KEY (shop_id) REFERENCES COFFEE_SHOP(shop_id); 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),

B-3 Develop SQL code to create a view by doing the following: a. Provide the SQL code you wrote to create your view. The view should show all of the information from the “Employee” table but concatenate each employee’s first and last name, formatted with a space between the first and last name, into a new attribute called employee_full_name. CREATE TABLE EMPLOYEE ( employee_id INT, first_name VARCHAR(30), last_name VARCHAR(30), hire_date DATE, job_title VARCHAR(30), shop_id INT, PRIMARY KEY (employee_id) ); CREATE TABLE COFFEE_SHOP ( shop_id INT, shop_name VARCHAR(50), city VARCHAR(50), state1 CHAR(2), PRIMARY KEY (shop_id) ); ALTER TABLE EMPLOYEE ADD FOREIGN KEY (shop_id) REFERENCES COFFEE_SHOP(shop_id); 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) );

CREATE TABLE SUPPLIER

( supplier_id INT, company_name VARCHAR(50), country VARCHAR(30), sales_contact_name VARCHAR(60), email VARCHAR(50) NOT NULL, PRIMARY KEY (supplier_id) ); ALTER TABLE COFFEE ADD FOREIGN KEY (supplier_id) REFERENCES SUPPLIER(supplier_id); INSERT INTO COFFEE_SHOP (shop_id, shop_name, city, state1) Values ('1', 'SJ Coffee', 'San Juan', 'PR'); INSERT INTO COFFEE_SHOP (shop_id, shop_name, city, state1) VALUES ('2', 'Doha Coffee', 'Doha', 'QT'); INSERT INTO COFFEE_SHOP (shop_id, shop_name, city, state1) VALUES ('3', 'Tampa Coffee', 'Tampa', 'FL'); INSERT INTO SUPPLIER (supplier_id, company_name, country, sales_contact_name, email) VALUES ('1', 'AKs Coffee Supplies', 'USA', 'John Bush', '[email protected]'); INSERT INTO SUPPLIER (supplier_id, company_name, country, sales_contact_name, email) VALUES ('2', 'Kyles Coffee Straws', 'USA', 'Kyle David', '[email protected]'); INSERT INTO SUPPLIER (supplier_id, company_name, country, sales_contact_name, email) VALUES ('3', 'All Supplies Needed', 'USA', 'Peter Thomas', '[email protected]'); INSERT INTO COFFEE (coffee_id, coffee_name, price_per_pound) VALUES ('1', 'Death Coffee', '7.99'); INSERT INTO COFFEE (coffee_id, coffee_name, price_per_pound) VALUES ('2', 'Vanilla Coffee', '4.99'); INSERT INTO COFFEE (coffee_id, coffee_name, price_per_pound) VALUES ('3', 'Custom Coffee', '5.99'); INSERT INTO EMPLOYEE (employee_id, first_name, last_name, hire_date, job_title, shop_id) VALUES ('1', 'Zack', 'Malcom', '20191123', 'Social Media Manager', '3'); INSERT INTO EMPLOYEE (employee_id, first_name, last_name, hire_date, job_title, shop_id) VALUES ('2', 'Walter', 'Jackson', '20220305', 'General Manager', '1'); INSERT INTO EMPLOYEE (employee_id, first_name, last_name, hire_date, job_title, shop_id) VALUES ('3', 'Dylan', 'McHugh', '20150718', 'Barista', '2'); CREATE VIEW employee_info AS SELECT "employee_id", CONCAT(EMPLOYEE.first_name, ' ', EMPLOYEE.last_name) employee_full_name, hire_date, job_title, shop_id FROM EMPLOYEE;

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) ); CREATE TABLE SUPPLIER ( supplier_id INT, company_name VARCHAR(50), country VARCHAR(30), sales_contact_name VARCHAR(60), email VARCHAR(50) NOT NULL, PRIMARY KEY (supplier_id) ); ALTER TABLE COFFEE ADD FOREIGN KEY (supplier_id) REFERENCES SUPPLIER(supplier_id); INSERT INTO COFFEE_SHOP (shop_id, shop_name, city, state1) Values ('1', 'SJ Coffee', 'San Juan', 'PR'); INSERT INTO COFFEE_SHOP (shop_id, shop_name, city, state1) VALUES ('2', 'Doha Coffee', 'Doha', 'QT'); INSERT INTO COFFEE_SHOP (shop_id, shop_name, city, state1) VALUES ('3', 'Tampa Coffee', 'Tampa', 'FL'); INSERT INTO SUPPLIER (supplier_id, company_name, country, sales_contact_name, email) VALUES ('1', 'AKs Coffee Supplies', 'USA', 'John Bush', '[email protected]'); INSERT INTO SUPPLIER (supplier_id, company_name, country, sales_contact_name, email) VALUES ('2', 'Kyles Coffee Straws', 'USA', 'Kyle David', '[email protected]'); INSERT INTO SUPPLIER (supplier_id, company_name, country, sales_contact_name, email) VALUES ('3', 'All Supplies Needed', 'USA', 'Peter Thomas', '[email protected]'); INSERT INTO COFFEE (coffee_id, coffee_name, price_per_pound) VALUES ('1', 'Death Coffee', '7.99'); INSERT INTO COFFEE (coffee_id, coffee_name, price_per_pound) VALUES ('2', 'Vanilla Coffee', '4.99'); INSERT INTO COFFEE (coffee_id, coffee_name, price_per_pound) VALUES ('3', 'Custom Coffee', '5.99'); INSERT INTO EMPLOYEE (employee_id, first_name, last_name, hire_date, job_title, shop_id) VALUES ('1', 'Zack', 'Malcom', '20191123', 'Social Media Manager', '3'); INSERT INTO EMPLOYEE (employee_id, first_name, last_name, hire_date, job_title, shop_id) VALUES ('2', 'Walter', 'Jackson', '20220305', 'General Manager', '1'); INSERT INTO EMPLOYEE (employee_id, first_name, last_name, hire_date, job_title, shop_id) VALUES ('3', 'Dylan', 'McHugh', '20150718', 'Barista', '2'); CREATE VIEW employee_info

AS SELECT "employee_id", CONCAT(EMPLOYEE.first_name, ' ', EMPLOYEE.last_name) employee_full_name, hire_date, job_title, shop_id FROM EMPLOYEE; CREATE INDEX coffee_name ON COFFEE (coffee_name); b. Demonstrate that you tested your code by providing a screenshot showing your SQL commands and the database server’s response. B-5 Develop SQL code to create an SFW (SELECT-FROM-WHERE) query for any of your tables or views by doing the following: a. Provide the SQL code you wrote to create your SFW query. SELECT* FROM EMPLOYEE; SELECT* FROM COFFEE_SHOP; SELECT* FROM COFFEE; SELECT* FROM SUPPLIER; SELECT*

FROM EMPLOYEE WHERE shop_id=1; SELECT* FROM COFFEE a LEFT JOIN COFFEE_SHOP b ON a.shop_id=b.shop_id LEFT JOIN EMPLOYEE c ON c.shop_id=a.shop_id LEFT JOIN SUPPLIER d ON d.supplier_id=a.supplier_id; b. Demonstrate that you tested your code by providing a screenshot showing your SQL commands and the database server’s response.

A. Construct a normalized physical database model

A-1 Complete the 2NF To obtain the second normal form (2NF) for the original table, it was necessary to create three tables: Bagel Order, Bagel Order Line Item, and Bagel. This was required so the non-key attributes would functionally depend on the primary key. Bagel Order ID is the primary key for the Bagel Order table, as is Bagel ID in the Bagel table. The third table, Bagel Order Line Item, takes both primary keys in the tables as foreign keys. This table is also the associative table, also known as the intersection table, of Bagel Order and Bagel. The relationship of Bagel Order and Bagel Order Line item from left to right is many-to-one. While being read from right to left, the association is one-to-many. This is because many order line items can be

placed in one Bagel Order, and a Bagel Order must contain, at least but not limited to, one item for an order. The cardinality when read is a many-to-one because of the two tables' relationship. The relationships between Bagel and Bagel Order Line Item are also many-to-one while being read from left to right and one-to-many in the opposite direction. A bagel can appear as a line item in multiple orders, but the order line needs to contain one or numerous bagels. When the cardinality is read from left to right, it is one-to-many.

A. Construct a normalized physical database model

A-1 Complete the 2NF To obtain the second normal form (2NF) for the original table, it was necessary to create three tables: Bagel Order, Bagel Order Line Item, and Bagel. This was required so the non-key attributes would functionally depend on the primary key. Bagel Order ID is the primary key for the Bagel Order table, as is Bagel ID in the Bagel table. The third table, Bagel Order Line Item, takes both primary keys in the tables as foreign keys. This table is also the associative table, also known as the intersection table, of Bagel Order and Bagel. The relationship of Bagel Order and Bagel Order Line item from left to right is many-to-one. While being read from right to left, the association is one-to-many. This is because many order line items can be placed in one Bagel Order, and a Bagel Order must contain, at least but not limited to, one item for an order. The cardinality when read is a many-to-one because of the two tables' relationship. The relationships between Bagel and Bagel Order Line Item are also many-to-one while being read from left to right and one-to-many in the opposite direction. A bagel can appear as a line item in multiple orders, but the order line needs to contain one or numerous bagels. When the cardinality is read from left to right, it is one-to-many.