INFO 2312 – Midterm 2
Date: Jul 29
th
, 2021
Time: 2 Hours 45 Minutes Due: 06.45 PM
Marks: 30 Marks
• The exam is open book and slides.
• No copying code from the internet is allowed.
• Separate spaces provided for query and screenshots of the answer.
• Not all questions need screenshots. Only answer what is asked in the question.If you do not find the box to paste the screenshot, then it is not needed.
• For any clarification during the midterm, call, or text @ +1-236-795-9045.
This study source was downloaded by 100000840858457 from CourseHero.com on 07-07-2022 04:17:04 GMT -05:00 https://www.coursehero.com/file/103221113/INFO-2312-Summer-2021-Midterm-II-Romeo-Tarrayopdf/
Consider the tables below. The csv files are attached with the exam in Moodle. The blank spaces are null values.
Employee
empno ename job mgr hiredate sal comm deptno
7369 SMITH CLERK 7902 17-12-1980 800 20
7499 ALLEN SALESMAN 7698 20-02-1981 1600 300 30
7521 WARD SALESMAN 7698 22-02-1981 1250 500 30
7566 JONES MANAGER 7839 02-04-1981 2975 20
7654 MARTIN SALESMAN 7698 28-09-1981 1250 1400 30
7698 BLAKE MANAGER 7839 01-05-1981 2850 30
7782 CLARK MANAGER 7839 09-06-1981 2450 10
7788 SCOTT ANALYST 7566 09-12-1982 3000 20
7839 KING PRESIDENT 17-11-1981 5000 10
7844 TURNER SALESMAN 7698 08-09-1981 1500 0 30
7876 ADAMS CLERK 7788 12-01-1983 1100 20
7900 JAMES CLERK 7698 03-12-1981 950 30
7902 FORD ANALYST 7566 03-12-1981 3000 20
7934 MILLER CLERK 7782 23-01-1982 1300 10
Department
deptno dname loc
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
1.Create a new login group role ‘student’ with password ‘12345’, provide login access, database creation access and replication access. Then create a Database ‘midterm2’ and make ‘student’ as the owner of the database. The query can be generated by the GUI as shown in class to create group roles and databases. Past both queries below. [5 Marks] CREATE ROLE student WITH LOGIN
NOSUPERUSER
CREATEDB
NOCREATEROLE
INHERIT
REPLICATION
CONNECTION LIMIT -1
PASSWORD 'xxxxxx';
CREATE DATABASE midterm2 WITH OWNER = student
ENCODING = 'UTF8'
CONNECTION LIMIT = -1;
This study source was downloaded by 100000840858457 from CourseHero.com on 07-07-2022 04:17:04 GMT -05:00 https://www.coursehero.com/file/103221113/INFO-2312-Summer-2021-Midterm-II-Romeo-Tarrayopdf/
- Paste SQL query to CREATE TABLE ‘employee’ and ‘department’. Make sure to include foreign
key. No Screenshot need only queries for the CREATE Table.
Paste Query to Create Table ‘employee’ [3 Marks] CREATE TABLE employee ( empno INT PRIMARY KEY, ename VARCHAR (100), job TEXT, mgr INT, hiredate DATE, sal NUMERIC, comm INT, deptno INT ); Paste Query to Create Table ‘department’ [2 Marks] CREATE TABLE department ( deptno INT PRIMARY KEY, dname VARCHAR (100), loc VARCHAR(100) );
- Write SQL Query to copy the result of selecting all columns in the Left join between employee
and department into another table name ‘employeedetails’.
Write the Query below. [4 Marks]
SELECT employee.empno, employee.ename, employee.job, employee.mgr, employee.hiredate, employee.sal, employee.comm, employee.deptno, department.deptno, department.dname, department.loc FROM employee LEFT JOIN department ON employee.empno = department.deptno
Paste the Screenshot of Running a SELECT * FROM employeedetails (which was created above). [1 Marks] This study source was downloaded by 100000840858457 from CourseHero.com on 07-07-2022 04:17:04 GMT -05:00 https://www.coursehero.com/file/103221113/INFO-2312-Summer-2021-Midterm-II-Romeo-Tarrayopdf/
- Write SQL query to list the employees who are either ‘CLERK’ or ‘ANALYST’ in the Desc order.
Write the Query below. [1 Marks] SELECT employee.empno, employee.ename, employee.job, employee.mgr, employee.hiredate, employee.sal, employee.comm, employee.deptno, department.deptno, department.dname, department.loc FROM employee LEFT JOIN department ON employee.empno = department.deptno ORDER BY employee.job DESC; Paste the Screenshot of the output here. [1 Marks]
- Write a Query to add another column updatedsalary with data type REAL to the employee table.
After that write, another Update query to fill the updatedsalary column with value being sal*1.05 (which shows an increment of 5% in salary) + the comm earned. There are few comm values that are NULL. NULL values cannot be added to another data type (doing that will give you error). So, you must make use of a function COALESCE([NULL], [VALUE]). If the first input parameter to this function is a NULL value, then whatever value is provided in the second input parameter, that value will replace the NULL values. This way all values can be replaced by 0 instead of NULL values along with the UPDATE query.
Query to ADD Column Below [2 Marks] This study source was downloaded by 100000840858457 from CourseHero.com on 07-07-2022 04:17:04 GMT -05:00 https://www.coursehero.com/file/103221113/INFO-2312-Summer-2021-Midterm-II-Romeo-Tarrayopdf/