Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Consider the following database. Employee has a unique eid, name, age and salary. Department has a unique did, name and an employee as a manager.

Consider the following database. Employee has a unique eid, name, age and salary. Department has a unique did, name and an employee as a manager. A department may or may not have a manager assigned. An employee can work for multiple departments. The pct_time in Works table is the percentage of time an employee works for a department. The salary of the employees is fixed and is not based on pct_time or the deparments they work in.

Emp (eid: INT(11), ename: VARCHAR(50), age: INT(11), salary: FLOAT)

Works (eid: INT(11), did: INT(11), pct_time: INT(11))

Dept (did: INT(11), dname: VARCHAR(50, managerid: INT(11))

Constraints

-eid is primary key for Emp table and cannot be NULL

-did is primary key for Dept table and cannot be NULL

-eid and did are foreign keys referencing to Emp and Dept tables respectively in Works table. combination of eid and did is the primary key or works table.

-managerid is foreign key referencing to Emp table and can have NULL values if the department doesnt have a manager assigned.

Sample values.

Emp

eid

ename

age

salary

1001

Georgi Facello

34

45000.00

1002

Parto Bamford

28

34000.00

1003

Christian Koblick

42

55000.00

1004

Saniya Peac

24

28000.00

Dept

did

dname

managerid

d001

Marketing

1003

d002

Finance

1002

d003

Information Security

NULL

Works

eid

did

pct_time

1001

d001

60

1002

d002

100

1003

d001

100

1001

d003

40

1004

d003

50

1004

d002

50

1. Create a new database named employee_db. Write the SQL statements required to create the above relations, including appropriate versions of all primary and foreign key integrity constraints. Submit all create table statements.

2. Write the insert statements to enter the above sample values to the database. Add 4 more employees, 2 more departments and assign the 4 new employees to departments with percentage time. Submit all insert statements.

3. Alter the table Emp to change the column age to dob with data type DATE and update the values based on their current age (should be approximate). Submit the alter and update table statement.

Write SQL queries for the following. Submit all queries. (5 points each)

1.Find the total salary of all employees.

2.Select the name and salary of the employee with the highest salary.

3.Select the department name and their respective manager name.

4.Select the employee names and their department names of the employees who work less than 50% of the time in that department.

5.Select the employee name and no of departments each employee works for.

6.Select the employee names with salary greater than average salary of all employees.

7.Select the department names with no manager assigned yet.

8.Select the employee names who work for more than 1 department.

9.Select the employee names and their manager names (keep in mind, one employee works for multiple departments so they will have multiple managers).

10.Select the name and salary of the employee with the second highest salary.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

OCA Oracle Database SQL Exam Guide Exam 1Z0-071

Authors: Steve O'Hearn

1st Edition

1259585492, 978-1259585494

More Books

Students also viewed these Databases questions

Question

5. Explain how ERISA protects employees pension rights.

Answered: 1 week ago