SQL
MySQL Administration & Simple Queries
Introduction - In this laboratory exercise you will gain initial experience with MySQL Server and the MySQL Workbench application.
Instructions – Create a Microsoft Word document. For each task, paste a screenshot (more than one if necessary) into a single Word document proving that you have carried out the task. Submit the document via Blackboard. Due date: 10/1/2020 7:00am.
Download/install MySQL Server and Workbench if you have not already done so. Start the server, open MySQL Workbench and create a connection for the root account. Connect to the server using this connection. The COMPANY database of the Elmasri/Navathe text (see Figure 5.5, e.g.) will be used throughout this assignment (and possibly more assignments). Carry out each of the following tasks from SQL Workbench.
1. From your MySQL Administrator (root account), create the company database (it will be empty – you will create the components of the schema, tables, later).
2. Create a user book and grant all rights on company to the user book (book is not an administrator, so should have no other rights). This can be done using a SQL command of the following form:
GRANT ALL PRIVILEGES
ON my_database.*
TO 'my_user'@'localhost'
IDENTIFIED BY 'my_password'
WITH GRANT OPTION;
The command can be all on one line, but having on multiple lines makes it easier to read. The ‘;’ terminates a single SQL command.
3. Create a MySQL Workbench connection for the book account. Use this connection to connect to the server. Choose the company database (if not part of your connection).
4. For each table in the company schema (see Figure 5.5), create a DDL statement to add the table to the database, then execute the statement. You may want to create a SQL script (file with extension .sql) for each statement to make it easier to create/modify the DDL statement. An example of such a statement is given in the file ‘employee.sql’ which is part of this assignment.
5. After you have created the tables in the company database, you need to fill them with data. Each table X has a file X.dat with data for that table attached to this assignment (these are text files, so have a look at them with your text editor). You will use the MySQL LOAD command to accomplish this. An example SQL script for loading the data into the employee table is attached to this assignment. Execute this script, and then a SQL ‘select *’ query to be sure that the data has been loaded. Create and execute scripts for the remaining tables, executing ‘select *’ to prove that the data has been loaded.
6. Create a query to retrieve the names of all employees in department 5 who work more than 10 hours per week on the ProductX project. Execute the query and show the results.
7. Create a query to list the names of all employees who have a dependent with the same first name as themselves. Execute the query and show the results.
8. Create a query to find the names of all employees who are directly supervised by ‘Franklin Wong’. Execute the query and show the results.
9. Create a query to change the location of department 8 from Chicago to Cleveland. Execute the query and show the results.
10. Create a query to add a new daughter born today named Sarah for Franklin Wong (make up a SSN for Sarah which is unique). Execute the query and show the results.
11. Create a query to delete the Computerization project. Execute the query and show the results.