Question: / * Create department table * / CREATE TABLE department ( dpt _ no INT PRIMARY KEY, dpt _ name VARCHAR ( 2 0 )

/* Create department table */
CREATE TABLE department (
dpt_noINT PRIMARY KEY,
dpt_name VARCHAR(20) NOT NULL,
dpt_mgrssn CHAR(9),
dpt_mgr_start_dateDATE);
/* Create dept_locations table */
CREATE TABLE dept_location (
dpt_no INT NOT NULL,
dpt_location VARCHAR(20),
PRIMARY KEY (dpt_no, dpt_location),
FOREIGN KEY (dpt_no) REFERENCES department(dpt_no));
/* Create project table */
CREATE TABLE project (
pro_numINT,
pro_nameVARCHAR(25) NOT NULL,
pro_locationVARCHAR(25),
pro_dept_num INT,
PRIMARY KEY (pro_num),
FOREIGN KEY (pro_dept_num) REFERENCES department(dpt_no));
/* Create employee table */
CREATE TABLE employee (
emp_ssnCHAR(9) PRIMARY KEY,
emp_last_nameVARCHAR(25) NOT NULL,
emp_first_nameVARCHAR(25) NOT NULL,
emp_middle_nameVARCHAR(25),
emp_addressVARCHAR(50),
emp_cityVARCHAR(15),
emp_stateCHAR(2),
emp_zipCHAR(9),
emp_date_of_birthDATE,
emp_salaryINT NOT NULL,
CONSTRAINT ck_emp_salary CHECK (emp_salary <=85000),
emp_parking_spaceINT UNIQUE,
emp_genderCHAR(1),
emp_dpt_numINT,
emp_superssnCHAR(9),
CONSTRAINT fk_emp_dpt FOREIGN KEY (emp_dpt_num) REFERENCES department(dpt_no),
CONSTRAINT fk_emp_superssn FOREIGN KEY (emp_superssn) REFERENCES employee(emp_ssn));
/* Create assignment table */
CREATE TABLE assignment (
work_emp_ssnCHAR(9),
work_pro_numINT,
work_hours INT,
work_hours_plannedINT,
CONSTRAINT pk_assignment PRIMARY KEY (work_emp_ssn, work_pro_num),
CONSTRAINT fk_work_empFOREIGN KEY (work_emp_ssn) REFERENCES employee(emp_ssn),
CONSTRAINT fk_work_pro_num FOREIGN KEY (work_pro_num) REFERENCES project(pro_num));
/* Create dependent table */
CREATE TABLE dependent (
dep_emp_ssnCHAR(9),
dep_nameVARCHAR(40),
dep_genderCHAR(1),
dep_date_of_birthDATE,
dep_relationshipVARCHAR(10) NOT NULL,
CONSTRAINT pk_dependent PRIMARY KEY (dep_emp_ssn, dep_name),
CONSTRAINT fk_dep_emp_ssn FOREIGN KEY (dep_emp_ssn) REFERENCES employee(emp_ssn));
1. Write a query to display all employees with the total number of projects they work on, including employees with no assignment. Display six columnsEmployee Name, department number and name, # of projects, the total actual hours, total planned hours and the difference. List the employee name as first and last name with a space in between. Sort the results by the department in ascending order, then # of projects in ascending order. Your name should be in the result list. See sample output below. (25 pts)
IMPORTANT: You need to research how to use IFNULL function. No partial credit, if the format of your results is different than provided in the sample output.
2. Write a query to display all employees, the total number of projects they worked on, and the total $ amount of the equipment used in those projects. If an employee does not have any assignment, you still must include those employees in the results list. Display four columnsEmployee SSN, Employee Name, # of Projects, and Equipment Total. Format the employee SSN as shown below. List the employee first and last name with a space between. Format the equipment total with a dollar sign as shown below. Sort the results by equipment total in ascending order. See sample output below. Your output must match the sample output. (25 pts)
IMPORTANT: You need to research how to use the FORMAT function and add $ sign in the results. No partial credit, if the format of your results is different than provided in the sample
3. Write a query to display projects that have the difference between hours planned and hours worked is more than 10. Display five columns. List the project number and name with a dash in between, name the column as Project, the total hours planned as Hours Planned, the total hours worked as Hours Worked, the difference, and the number of employees worked in each project. Sort the results in descending order by the difference. See sample output below. Your output must match the sample output. (25 pts)
4. Write a query to display the managers SSN, managers first and last name with a space between them, department number, department name, employees SSN, employees first and last name with a space between them, and the following information about the employee's dependents: name, relationship and date of birth. The department number and name are that of the employee, not the manager. Name the columns as follows: Manager SSN, Manager Name, Department, Employee SSN, Employee Name, Dependent Name, Relationship and Dependent DOB. Sort the results by department number, employee SSN in all ascending order. See sample output below. (25 pts)
IMPORTANT: You need to research how to use SUBSTRING and DATE_FORM

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!