Labs Cognitiveclass Ai
Labs Cognitiveclass Ai
appdo…
+
-
Helvetica N...
▼
Step 1 of 15
Congratulations!! You have finished the modules. Now is the time to put your skills to test. Read through the scenario below.
Scenario
In this scenario, you have recently been hired as a Data Engineer by a New York based coffee shop chain that is looking to expand nationally by
opening a number of franchise locations. As part of their expansion process, they want to streamline operations and revamp their data infrastructure.
Your job is to design their relational database systems for improved operational efficiencies and to make it easier for their executives to make data
driven decisions.
Currently their data resides in several different systems: accounting software, suppliers’ databases, point of sales (POS) systems, and even
spreadsheets. You will review the data in all of these systems and design a central database to house all of the data. You will then create the database
objects and load them with source data. Finally, you will create subsets of data that your business partners require, export them, and then load them
into staging databases that use different RDBMS.
You will use a modified version of the data for the project, so to succeed in the project, download the linked files when prompted in the instructions.
You do not need to use any data from the original source.
In your scenario, you will be working with data from the following sources:
Objectives
After completing this lab, you will be able to:
Identify entities.
Identity attributes.
Create an entity relationship diagram (ERD) using the pgAdmin ERD Tool.
Normalize tables.
Define keys and relationships.
Create database objects by generating and running the SQL script from the ERD Tool.
Create a view and export the data.
Create a materialized view and export the data.
https://labs.cognitiveclass.ai/tools/theiadocker/?md_instructions_url=https%3A%2F%2Ffanyv88.com%3A443%2Fhttps%2Fcf-courses-data.s3.us.cloud-object-storage.appdomain.cloud%2FIBM-D… 1/5
13/10/2021, 11:55 https://labs.cognitiveclass.ai/tools/theiadocker/?md_instructions_url=https%3A%2F%2Ffanyv88.com%3A443%2Fhttps%2Fcf-courses-data.s3.us.cloud-object-storage.appdo…
Import data into a Db2 database.
Import data into a MySQL database.
1. The following image shows sample data from each of the data sources that you will be working with to design your new central database.
Review the image and identify the entities you plan to create.
Note: You might find it useful to download a copy of this image or open it in another browser tab for reference later in the lab.
1. Using the information from the sample data in the image from Task 1, identify the attributes for the entity that will store the sales transaction
data.
https://labs.cognitiveclass.ai/tools/theiadocker/?md_instructions_url=https%3A%2F%2Ffanyv88.com%3A443%2Fhttps%2Fcf-courses-data.s3.us.cloud-object-storage.appdomain.cloud%2FIBM-D… 2/5
13/10/2021, 11:55 https://labs.cognitiveclass.ai/tools/theiadocker/?md_instructions_url=https%3A%2F%2Ffanyv88.com%3A443%2Fhttps%2Fcf-courses-data.s3.us.cloud-object-storage.appdo…
1. Open a new terminal from the side-by-side Cloud IDE.
2. Use the start_postgres command to start a PostgreSQL service session in the Cloud IDE.
3. Use the pgAdmin weblink to open pgAdmin in a new tab in your browser.
4. Create a new database named COFFEE, view the schemas in the new COFFEE database, and then start a new ERD project.
5. Add a table to the ERD for the sale transactions entity using the information in the following table. Consider what naming convention to use so
that your colleagues will be able to understand your data and to ensure that the names are valid in other RDBMS. And use the sample data
shown in the image in Task 1 to determine appropriate data types for each column.
7. Add a table to the ERD for the product entity using the information in the following table. Consider what naming convention to use so that your
colleagues will be able to understand your data and to ensure that the names are valid in other RDBMS. And use the sample data shown in the
image in Task 1 to determine appropriate data types for each column.
1. Review the data in the sales transaction table. Note that the transaction id column does not contain unique values because some transactions
include multiple products.
2. Determine which columns should be stored in a separate table to remove the repeating rows and to put this table into second normal form.
3. Add a new table named sales_detail to the ERD, define the columns in the new table, and delete the moved columns from the sales
transaction table, leaving a matching column in each of two tables to later create a relationship between them.
5. Review the data in the product table. Note that the product category and product type columns contain redundant data.
6. Determine which columns should be stored in a separate table to reduce redundant data and to put this table into second normal form.
7. Add a new table named product_type to the ERD, define the columns in the new table, and delete the moved columns from the product table, ,
leaving a matching column in each of two tables to later create a relationship between them.
1. Identify an appropriate column in each table to be a primary key and create the primary keys in the tables in your ERD.
3. Identify the relationships between the following pairs of tables and then create the relationships in your ERD:
sales_detail to sales_transaction
https://labs.cognitiveclass.ai/tools/theiadocker/?md_instructions_url=https%3A%2F%2Ffanyv88.com%3A443%2Fhttps%2Fcf-courses-data.s3.us.cloud-object-storage.appdomain.cloud%2FIBM-D… 3/5
13/10/2021, 11:55 https://labs.cognitiveclass.ai/tools/theiadocker/?md_instructions_url=https%3A%2F%2Ffanyv88.com%3A443%2Fhttps%2Fcf-courses-data.s3.us.cloud-object-storage.appdo…
sales_detail to product
product to product_type
Task 6: Create database objects by generating and running the SQL script from the ERD Tool
Now that your design is complete, you will generate an SQL script from your ERD which you could use to create your database schema. For the
purposes of this project, you will then use a provided SQL script to ensure that you will be able to successfully load the sample data into the schema.
Finally, you will load the existing data from the various data sources into your new database schema.
1. Use the Generate SQL functionality in the ERD Tool to create an SQL script from your ERD.
GeneratedScript.sql
3. In pgAdmin, open the Query Tool, upload and open the GeneratedScript.sql file from your local computer storage, and then execute the
script to create the tables defined in the ERD. Verify that the tables now exist in the public schema of the COFFEE database.
4. Take a screenshot of the tables shown in the tree-view pane on the left-hand side of the page and save it as Task6A.png or Task6A.jpg.
CoffeeData.sql
6. In pgAdmin, open another instance of the Query Tool, upload and open the CoffeeData.sql file from your local computer storage, and then
execute the script to populate the tables you just created.
8. Take a screenshot of the Data Output pane and save it as Task6B.png or Task6B.jpg.
1. In your COFFEE database, create a new view named staff_locations_view using the following SQL:
SELECT staff.staff_id,
staff.first_name,
staff.last_name,
staff.location
FROM staff
WHERE "position" NOT IN ('CEO', 'CFO');
3. Save the results of the query to a file named staff_locations_view.csv on your local computer storage.
4. Take a screenshot of the view shown in the tree-view pane on the left-hand side of the page alongside the results in the Data Output pane, and
save it as Task7.png or Task7.jpg.
1. In your COFFEE database, create a new materialized view named product_info_m-view using the following SQL:
SELECT product.product_name, product.description, product_type.product_category
FROM product
JOIN product_type
ON product.product_type_id = product_type.product_type_id;
4. Save the results of the query to a file named product_info_m-view.csv on your local computer storage.
5. Take a screenshot of the view shown in the tree-view pane on the left-hand side of the page alongside the results in the Data Output pane, and
save it as Task8.png or Task8.jpg.
1. In a new browser tab, go to https://cloud.ibm.com/login, log in using your credentials, and then open a console for your Db2 on Cloud instance
that you created earlier in this course.
https://labs.cognitiveclass.ai/tools/theiadocker/?md_instructions_url=https%3A%2F%2Ffanyv88.com%3A443%2Fhttps%2Fcf-courses-data.s3.us.cloud-object-storage.appdomain.cloud%2FIBM-D… 4/5
13/10/2021, 11:55 https://labs.cognitiveclass.ai/tools/theiadocker/?md_instructions_url=https%3A%2F%2Ffanyv88.com%3A443%2Fhttps%2Fcf-courses-data.s3.us.cloud-object-storage.appdo…
2. Use the Load Data feature to load a new table named STAFF_LOCATIONS with the staff location information saved in the
staff_locations_view.csv file that you exported from the view you created in Task 7.
3. Explore the new table and then view the data in it.
4. Take a screenshot of the contents of the new table and save it as Task9.png or Task9.jpg.
1. In the terminal from the side-by-side Cloud IDE, use the start_mysql command to start a My SQL service session in the Cloud IDE.
2. Use the browser weblink to open phpMyAdmin in a new tab in your browser.
3. In phpMyAdmin, create a new database named coffee_shop_products, and then import the product information saved in the
product_info_m-view.csv file from your materialized view into a new table in the coffee_shop_products database.
5. Take a screenshot of the contents of the new table and save it as Task10.png or Task10.jpg.
Author(s)
Lin Joyner
Other Contributor(s)
*
Changelog
Date Version Changed by Change Description
2021-04-01 1.0 Lin Joyner Created initial version
Continue
https://labs.cognitiveclass.ai/tools/theiadocker/?md_instructions_url=https%3A%2F%2Ffanyv88.com%3A443%2Fhttps%2Fcf-courses-data.s3.us.cloud-object-storage.appdomain.cloud%2FIBM-D… 5/5