CIS4301 - Quiz 3

Problem 1

Page 1 of 3

Consider the following schema: Employee(Fname, Minit, Lname, SSN, Bdate, Address, Sex, Salary, Super_ssn, Dno) Department(Dname, Dnumber, Mgr_ssn, Mgr_start_date) Dept_locations(Dnumber, Dlocation) Project(Pname, Pnumber, Plocation, Dnum) Works_on(Essn, Pno, Hours) Dependent(Essn, Dependent_name, Sex, Bdate, Relationship)

Accomplish the following tasks in SQL.

(1)

Delete all projects on which nobody works on.

Solution. DELETE FROM Project WHERE Pnumber NOT IN (SELECT Pno FROM WORKS_ON);

(2)

Update the location of departments located in EE to CSE (a move of everybody from EE to CSE building). Solution. UPDATE Dept_locations SET Dlocation = ’CSE’ WHERE Dlocation = ’EE’;

(3)

For the departments without a location but has a single project, set the location of the department as the location of the project (Dlocation becomes Plocation). You have to write an INSERT statement to do this.

INSERT INTO Dept_locations SELECT Dnum, Plocation FROM Project WHERE Dnum IN ( (SELECT Dnum FROM Project GROUP BY Dnum HAVING COUNT(Pnumber) = 1) EXCEPT (SELECT Dnumber FROM Dept_locations));

(4)

Write an assertion that ensures that every Employee works on at most 5 projects.

CREATE ASSERTION a1 CHECK (

CIS4301 - Quiz 3

Page 2 of 3

5 >= ALL (SELECT COUNT(Pno) GROUP BY Essn));

(5)

Write a trigger that ensures that employees are managed by department managers; that is, the Super ssn is the ssn of the manager of the department in which the project on which the employee works on is hosted. More specically, upon insertions of tuples in Works on that are not consistent with this constraint, change the Super ssn to the ssn of the department manager that manages the project in which the employee works on.

CREATE TRIGGER FixSuperSSN AFTER INSERT ON Works_on REFERENCING NEW ROW AS NewRow FOR EACH ROW BEGIN UPDATE Employee SET Super_ssn = (SELECT Mgr_ssn FROM Department, Project, Works_on WHERE Department.Dname = Project.Dnum AND Project.Pnumber = Works_on.Pno AND Works_on.Essn = NewRow.Essn) WHERE Employee.SSN = NewRow.Essn; END;

Problem 2

Consider the following schema from Quiz 2: Flights(flno, from, to, distance, departs, arrives, price) Aircraft(aid, aname, cruisingrange) Certified(eid, aid) Employees(eid, ename, salary)

Write the following queries in Relational Algebra. (Note: Please read the questions carefully before you write; they are similar but different from those of Quiz 2.)

(1)

Find the names of pilots who are not certified for any Boeing aircraft.

Solution. πename (Employees o n Certified)− πename (σaname=’Boeing’ (Employees o n Certified o n Aircraft))

CIS4301 - Quiz 3

Page 3 of 3

(2)

Find the names of aircraft such that the average salary of all pilots certified to operate them is more than $80,000. Solution. πaname (σavg>80,000 (γaid, AVG(salary)→avg (Employees o n Certified o n Aircraft)))

Problem 1 Consider the following schema ...

Problem 1 Consider the following schema: Employee(Fname, Minit, Lname, SSN, Bdate, Address, Sex,. Salary, Super_ssn, Dno). Department(Dname, Dnumber ...

117KB Sizes 4 Downloads 168 Views

Recommend Documents

Consider Your Hungry Shark Evolution Hack To The Following ...
Consider Your Hungry Shark Evolution Hack To The Following Level With These Amazing Hints.pdf. Consider Your Hungry Shark Evolution Hack To The ...

Solve the following problems of Chapter 5: Problem ...
Solve the following problems of Chapter 5: Problem No. 2. Problem No. 3. Problem No. 5. Problem No. 8. Problem No. 11. Problem No. 15. Problem No. 18.

Schema Powerbuilding 1.pdf
Preacher curl 60 sec 3 12. Russian Twist 60 sec 3 10. Page 2 of 2. Schema Powerbuilding 1.pdf. Schema Powerbuilding 1.pdf. Open. Extract. Open with. Sign In.

Problem Set 1: C
Sep 17, 2010 - Simply email [email protected] to inquire; be sure to mention your full name, your ..... Now let's add those products' digits (i.e., not the products themselves) .... http://code.google.com/apis/chart/docs/gallery/bar_charts.html.

Problem Set 1: C
Sep 17, 2010 - on cloud.cs50.net as well as filling out a Web-‐based form, which may take a ... virtual terminal room) or lifting material from a book, website, or.

Problem 1 Problem 2 Problem 3 -
roads through the forest are both extremely important, so a boy who reaches the age of manhood is not designated ... first hike is a 5 kilometer hike down the main road. The second hike is a 51. 4 kilometer ..... from one state to another with two cl

problem 1 -
The table PERSON contains the attributes namely driver_id, name & address ... The table CAR contains the attributes such as model, year & register number ..... The average order amount can be obtained by considering the total cost per order. ...... e

Problem Set 1: C
Problem Set 1: C due by 7:00pm on Fri 9/17. Per the directions at this document's end, submitting this problem set involves submitting source code.

problem 1 -
Hence ONO and INO act as the foreign keys for this relation. Warehouse : This relation contains information about the warehouses of the company. It keeps track ...

problem 1 -
This relation contains information about the warehouses of the company. It keeps .... COURSES OFFERED BY THE CS DEPARTMENT THAT USE MORE THAN.

1 Problem -
Page 1. 1 Problem. Find the solution of the following differential equation: dy dx. + ycotx = 2x + x2cotx x = 0, given y = 0 when x = π. 2. 1.

Problem Set 1: C
Sep 17, 2010 - Nor may you provide or make available solutions to problem sets to individuals who .... Simply email [email protected] to inquire; be sure to mention your full name, your ..... 21 http://www.nist.gov/dads/HTML/greedyalgo.html .... Anyhow,

problem 1 -
The table PERSON contains the attributes namely driver_id, name & address where ... The table CAR contains the attributes such as model, year & register number ...... each attribute is given a name, a data type to specify its domain of values ...

1. Perform the following using proper precision or ...
A glass container weighs 25.60 g empty and 35.55 g when filled with water at 20.0˚C. The density of water at 20˚C is 0.998 g/cm3. When 10.20 g of lead shot are ...

Exercise 1: Rerwite the following sentences that keep ...
Although he is intelligent, he doesn't do well at school. --> In spite of ... The Watsons moved to London and very soon after they decided to get divorced ... 85. They regret ever doing business with him. They wish ...

5 1. Answer the following multiple choice questions
questions from Section A are compulsory. Attempt any three questions from Section B. SECTION A. 1. Answer the following multiple choice questions : 10x1=10.

5 1. Answer the following multiple choice questions
(Weightage : 75%). Note : There are two sections in this paper. All the questions from Section A are compulsory. Attempt any three questions from Section B. SECTION A. 1. Answer the following multiple choice questions : 10x1=10. (i) The two main part

FOLLOWING THE MESSAGE 1.) According to ... - New Hope Church
Msg-Tough Grace - Titus Pt 2. Titus 1:5-10 1/16/11. FOLLOWING THE MESSAGE. 1.) According to Proverbs 29:2 and the principles from Titus Ch 1, qualified ...

1.In which of the following lubrication system ... Accounts
Ans:A. 48.The device used to convert AC current in the armature coil to DC current is: A.Yoke ... A.I section*. B.L section ... B.Catalytic converter. C.Supercharger.

FOLLOWING THE MESSAGE 1.) According to ... - New Hope Church
Jan 16, 2011 - The Bible tells us a man should “ASPIRE” to the office of Elder, rather than talking him into it through persuasion. This is especially important.

CE 572 Stability of Structures Home Work #1 1. Consider the system ...
Consider the system shown below with ... system in the indicated coordinate (θ). a. ... Determine the elastic buckling loads for the following system comprising of ...

1 Site Zoning Vignette: 1 hour total 1 problem with 2 tasks Problem ...
General notes / Tips: • Exact problem w/ single answer. • Follow the program exactly. • Be aware of sun exposure planes; corner of building will likely be clipped.

1 Math Review Problem 2 Macro Review Problem
Consider the two period endowment economy in the Macro Review slides: a household is endowed with Q1 units of goods in period one and Q2 units of goods in period two. The goods are perishable, hence the household cannot store the endowment from perio