• Home
  • Blog
  • DAD 220 SNHU Module 3 Create a Program Code Typedprior MySQL Task

DAD 220 SNHU Module 3 Create a Program Code Typedprior MySQL Task

0 comments

Overview

Table joins are commonly used to return records from multiple tables in a normalized database for the purpose of generating reports and performing ad-hoc queries. Since data does not all reside in one large table in a normalized database, we use joins to retrieve supporting information for the records we are searching for. Joins connect tables by matching values of keys in the tables to retrieve related records, generally using the SELECT and WHERE commands. For example, if customer_ID is used in a customer table and in an order table, the join would use the CUSTOMER-ID to connect the CUSTOMER table and the ORDER table to create a combined record for each key value matched in the two tables.

Prompt

The manager of a small marketing firm has asked you to identify information on new hires that work at her company. You’ve already entered some information for the new hires, but you will need to enter more. After entering the remaining new information, perform a join that will produce the results requested by the manager. Then, you will need to write the query to save the results and write them to a comma-separated values (CSV) file, which is a delimited text file that uses a comma to separate values so they can be archived. Please revisit the instructions from the Module Two lab to identify the data you will need.

  1. Before you begin, type the following commands prior to typing MySQL to set file permissions. This will allow you to perform the file output creation: 
    1. chmod +x change_perm.sh and then
    2. ./change_perm.sh
    3. Then, enter a command line session with MySQL and reconnect to the employee information you entered in the previous lab.
    4. Write a SELECT statement for the Employee table to check that you have reconnected to the right information.
  2. Update the name of the Branches table that you created in the previous lab to say “Department.”
    1. Use an ALTER statement to successfully RENAME the “Branches” table to “Department.”
    2. Capture these outputs in a screenshot to validate that you have successfully completed this step.
  3. Insert fields to the Department table so that you will be able to perform joins on them. 
    1. INSERT INTO Department VALUES
      (1, ‘Accounting’),
      (2, ‘Human Resources’),
      (3, ‘Information Systems’),
      (4, ‘Marketing’);
    2. Write a SELECT statement for this table to prove this step and validate that it ran correctly with a screenshot.
  4. Now, perform joins between the Department and Employee tables and show results for how many employees work in each one of the four departments. This will only provide information on the records that are already there. 
    1. Department 1 = Accounting 
      1. Command: select First_Name, Last_Name, Department.Department_Name from Employee inner join Department on Employee.Department_ID = Department.Department_ID where Employee.Department_ID = 1;
    2. Using SELECT statements similar to the one above, perform joins to produce results for the following records: 
      1. Department 2 = Human Resources
      2. Department 3 = Information Systems
      3. Department 4 = Marketing
    3. Capture the results of these joins and validate your work by providing a screenshot. You should have the same number of records as you do employees.
  5. Populate the Employee table with information for ten new employees. Give them unique names and include attributes for all necessary fields. (Note: Please reference attributes from the lab in Module Two. Department ID values must be between 1 and 4.)
  6. Perform a join across the Employee and Department Tables for each of the four departments. New and existing records should be displayed in the results. 
    1. Take a screenshot to capture the updated results that the Employee and Department joins show to validate that they have run correctly. You should have the same number of records as you do employees.
  7. Identify the resultant outputs of the commands that you have written:
    1. How many records are returned for employees in each department?
  8. Create a CSV file that contains only the records of employees in Human Resources and Information Systems. If you run this query multiple times, be sure to use a different file name each time. MySQL will not overwrite an existing file. 
    1. Enter the command listed below. 
      1. Command: select First_Name, Last_Name, Department.Department_Name from Employee inner join Department on Employee.Department_ID = Department.Department_ID where Employee.Department_ID = 3 OR Employee.Department_ID = 2 into outfile’/home/codio/workspace/HRandIS-Employees.csv’ FIELDS TERMINATED BY’,’;
    2. Print the file output to the screen. 
      1. You’ll need to type the word quit after your MySQL prompt and then press Enter to exit to the Linux shell. Do not exit the virtual lab environment itself.
      2. Next, print the output of your file to the screen by following these steps:
        1. Type pwd and press Enter, then type ls and press Enter again. This will list your files.
        2. Now, type cat HRandIS-Employees.csv and press Enter.
        3. Capture these outputs in a screenshot to validate that you have successfully completed this step.
  9. Reflections: Provide detailed insight on the prompts below by explaining your process along with how and why it ultimately worked. 
    1. Process 
      1. Explain how the joins you used in this assignment worked.
      2. Describe why the commands you used were able to retrieve the Department table when you selected the Department name.
    2. File creation and extraction 
      1. When you write the records of your query to a CSV file, how many records are in the file?
      2. Provide a detailed explanation of how the process of extracting data to a flat file works.

About the Author

Follow me


{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}