abu-vht2-vht2-task-1-vht2-task-1-normalization-and-database-design_DA

docx

School

University of Texas *

*We aren’t endorsed by this school

Course

6233

Subject

Computer Science

Date

Jan 9, 2024

Type

docx

Pages

17

Uploaded by BarristerMaskHare36

Report
Downloaded by Da'Juan Mosley (drduke94@hotmail.com) ABU VHT2 VHT2 TASK 1 - VHT2 TASK 1: NORMALIZATION AND DATABASE DESIGN Data Management Applications (Western Governors University) Studocu is not sponsored or endorsed by any college or university
Downloaded by Da'Juan Mosley (drduke94@hotmail.com) VHT2 VHT2 TASK 1: NORMALIZATION AND DATABASE DESIGN A. Construct a normalized physical database model to represent the ordering process for Nora’s Bagel Bin by doing the following: 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. Solution: -> One bagel item can be included in more than one bagel order. -> A bagel order id in the bagel order line item relates to just one order id. As a result, this is a 1:M ratio (one-to-many)
Downloaded by Da'Juan Mosley (drduke94@hotmail.com) -> A bagel item belongs to just one bagel id in the bagel order line item, however a bagel item can be requested by many orders. As a result, the M:1 ratio applies (many-to-one). -> Each attribute in the table is allocated by taking partial dependence into account in the 1NF. The Bagel ID determines the Bagel Name, Bagel Description, and Bagel Price. The Bagel Order ID determines the Order Date, First Name, Last Name, Address1, Address2, City, State, Zip, Mobile Phone, Delivery Fee, and Special Notes. As a result, the properties are assigned based on the dependence. 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). e. Explain how you assigned attributes to the 3NF tables and determined the cardinality of the relationships between your 3NF tables .
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Downloaded by Da'Juan Mosley (drduke94@hotmail.com) Repeated data was moved to a new table called CUSTOMER. Customer ID is a new primary key for the table CUSTOMER, and it is used as a foreign key in the BAGEL ORDER table. One customer can place many orders, but only one customer can place an order. As a result, the relationship is M:1 (many-to-one). 3. Complete the "Final Physical Database Model" section of the attached “Nora’s Bagel Bin Database Blueprints” document by doing the following: a. Copy the table names and cardinality information from your 3NF diagram into the “Final Physical Database Model” and rename the attributes. b. Assign one of the following five data types to each attribute in your 3NF tables: CHAR(), VARCHAR(), TIMESTAMP, INTEGER, or NUMERIC(). Each data type must be used at least once. Solution: The final physical database model is as shown:
Downloaded by Da'Juan Mosley (drduke94@hotmail.com) B. Create a database using the attached "Jaunty Coffee Co. ERD" by doing the following: 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 the tables. b. Demonstrate that you tested your code by providing a screenshot showing your SQL commands and the database server’s response. Solution: -- SQL code for table `coffee_shop` CREATE TABLE coffee_shop ( shop_id INTEGER NOT NULL, shop_name varchar(50) NOT NULL, city varchar(50) NOT NULL, state char(2) NOT NULL, PRIMARY KEY (shop_id) );
Downloaded by Da'Juan Mosley (drduke94@hotmail.com) Result: -- SQL code for table `supplier` CREATE TABLE supplier ( supplier_id INTEGER NOT NULL, company_name varchar(50) NOT NULL, country varchar(30) NOT NULL, sales_contact_name varchar(60) NOT NULL, email varchar(50) NOT NULL, PRIMARY KEY (supplier_id) );
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Downloaded by Da'Juan Mosley (drduke94@hotmail.com) Result: -- SQL code for table 'employee' CREATE TABLE employee ( employee_id INTEGER NOT NULL, fi rst_name varchar(30) NOT NULL, last_name varchar(30) NOT NULL, hire_date date NOT NULL, job_title varchar(30) NOT NULL, shop_id INTEGER NOT NULL, PRIMARY KEY (employee_id), FOREIGN KEY (shop_id) REFERENCES coffee_shop(shop_id ) );
Downloaded by Da'Juan Mosley (drduke94@hotmail.com) Result: -- SQL code for table `coffee` CREATE TABLE coffee ( coffee_id INTEGER NOT NULL, shop_id INTEGER NOT NULL, supplier_id INTEGER NOT NULL, coffee_name varchar(30) NOT NULL, price_per_pound NUMERIC(5,2) NOT NULL, PRIMARY KEY (coffee_id), FOREIGN KEY (shop_id) REFERENCES coffee_shop(shop_id ), FOREIGN KEY (supplier_id) REFERENCES supplier(supplier_id) );
Downloaded by Da'Juan Mosley (drduke94@hotmail.com) Result: 2. Develop SQL code to populate each table in the database design document by doing the following: Note: This data is not provided. You will be fabricating the data for this step. a. Provide the SQL code you wrote to populate the tables with at least three rows of data in each table. b. Demonstrate that you tested your code by providing a screenshot showing your SQL commands and the database server’s response. Solution:
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Downloaded by Da'Juan Mosley (drduke94@hotmail.com) -- Insert data for table 'coffee_shop' INSERT INTO coffee_shop (shop_id, shop_name, city, state) VALUES(1, 'Shop 1', 'city_name', 'NY’); INSERT INTO coffee_shop (shop_id, shop_name, city, state) VALUES(2, 'Shop 2', 'city_name', 'NY'); INSERT INTO coffee_shop (shop_id, shop_name, city, state) VALUES(3, 'Shop 3', 'city_name', 'NY’); -- Insert data for table 'employee' INSERT INTO employee (employee_id, fi rst_name, last_name, hire_date, job_title, shop_id) VALUES(1, 'Fname 1', 'Lname 1', '2021-09-11', 'Job 1', 1); INSERT INTO employee (employee_id, fi rst_name, last_name, hire_date, job_title, shop_id) VALUES(2, 'Fname 2', 'Lname 2', '2021-11-03', 'Job 1', 2); INSERT INTO employee (employee_id, fi rst_name, last_name, hire_date, job_title, shop_id) VALUES(3, 'Fname 3', 'Lname 3', '2021-11-05', 'Job 1', 3); -- Insert data for table 'supplier ' INSERT INTO supplier (supplier_id, company_name, country, sales_contact_name, email) VALUES(1, 'Company 1', 'USA', 'scName1', 'supp1@abc.com'); INSERT INTO supplier (supplier_id, company_name, country, sales_contact_name, email)
Downloaded by Da'Juan Mosley (drduke94@hotmail.com) VALUES(2, 'Company 2', 'USA', ' scName2', 'supp2@abc.com'); INSERT INTO supplier (supplier_id, company_name, country, sales_contact_name, email) VALUES(3, 'Company 3', 'USA', 'scName3', 'supp3@mail.com'); -- Insert data for table 'coffee' INSERT INTO coffee (coffee_id, shop_id, supplier_id, coffee_name, price_per_pound) VALUES(1, 1, 1, 'Name 1',16 ); INSERT INTO coffee (coffee_id, shop_id, supplier_id, coffee_name, price_per_pound) VALUES(2, 2, 2, 'Name2', 18); INSERT INTO coffee (coffee_id, shop_id, supplier_id, coffee_name, price_per_pound) VALUES(3, 3, 3, 'Name3', 12);
Downloaded by Da'Juan Mosley (drduke94@hotmail.com) Select Data From Table "coffee_shop" SELECT * FROM coffee_shop; Result: Select Data From Table "employee" SELECT * FROM employee; Result:
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Downloaded by Da'Juan Mosley (drduke94@hotmail.com) Select Data From Table "supplier" SELECT * FROM supplier; Result: Select Data From Table "coffee" SELECT * FROM coffee; Result:
Downloaded by Da'Juan Mosley (drduke94@hotmail.com) 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. b. Demonstrate that you tested your code by providing a screenshot showing your SQL commands and the database server’s response. Solution: SQL code: CREATE VIEW Employee_View AS SELECT employee_id, CONCAT( fi rst_name, ' ', last_name) AS employee_full_name, hire_date, job_title,shop_id FROM employee View Data From View - SELECT * FROM Employee_View; Result :
Downloaded by Da'Juan Mosley (drduke94@hotmail.com) 4. Develop SQL code to create an index on the coffee_name field by doing the following: a. Provide the SQL code you wrote to create your index on the coffee_name field from the “Coffee” table. b. Demonstrate that you tested your code by providing a screenshot showing your SQL commands and the database server’s response. Solution: SQL code: CREATE INDEX index1 ON coffee (coffee_name); Result : 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. b. Demonstrate that you tested your code by providing a screenshot showing your SQL commands and the database server’s response.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Downloaded by Da'Juan Mosley (drduke94@hotmail.com) Solution: SQL code: SELECT * FROM coffee WHERE price_per_pound > 15; Result: 6. Develop SQL code to create a query by doing the following: a. Provide the SQL code you wrote to create your table joins query. The query should join together three different tables and include attributes from all three tables in its output. b. Demonstrate that you tested your code by providing a screenshot showing your SQL commands and the database server’s response. Solution: SQL code: SELECT * FROM coffee, coffee_shop, supplier WHERE coffee.shop_id = coffee_shop.shop_id AND coffee.supplier_id = supplier.supplier_id
Downloaded by Da'Juan Mosley (drduke94@hotmail.com) Result :