Sie sind auf Seite 1von 3

Department of Electrical Engineering

UNIVERSITY OF ENGINEERING & TECHNOLOGY, Lahore

EE-436 Database Engineering


Mid Term Exam Solution
Question1: [5 points] Given the ER Diagram Below. Create its Relational Schema Database. Cardinality Ratios are
mentioned at each side of relation. (0,N) represents partial participation in the relation. (CLO1)

EMPLOYEE
EmployeeNo FName LName ZipCode

CUSTOMER
CustomerNo FName LName ZipCode

ORDER
OrderNo DateReceipt DateExpected DateShipped EmployeeNo CustomerNo

PART
PartNo Name Price QuantityInStock

ORDER_CONSISTS
OrderNo PartNo Quantity

Question 02 [1+1+1+1+1 points]: Suppose that each of the following update operation is applied independently to
the database shown in Figure 5.6. If the update is a valid one (ignore the syntax errors if there is any), just write
“Valid”, otherwise, indicates it is “Invalid” and explicitly indicate why it is invalid based on all the constraints you
have studied so far. (SET NULL is the default option for delete). (CLO2)
a) Insert < 'Robert', 'F', 'Scott', '66622', '1941-06-42', '2365 Newcastle Rd, Bellaire, TX', M, 58000,
'888665555', 1 > into EMPLOYEE.
ANSWER:
INVALID: Violate SSN Domain Constraint

b) Insert < 'Production', 3, '943775543', '1988-05-22' > into DEPARTMENT.


ANSWER:
INVALID, violate referential constrain on Mgr_ssn attribute (943775543 is not exist in EMPLOYEE)

c) Modify the MGRSSN and MGRSTARTDATE of the DEPARTMENT tuple with DNUMBER=2 to
'123456789' and '2011-10-17', respectively.
ANSWER:
INVALID, DNUMBER=2 is not existed

d) Modify the SUPERSSN attribute of the EMPLOYEE tuple with SSN= '999887777' to 888665555'.
ANSWER:
VALID

e) Modify the HOURS attribute of the WORKS_ON tuple with ESSN= '999887777' and PNO= 10 to '5.0'.
ANSWER:
VALID

Question 03 [2+2+2 points]: Answer these questions. (CLO1)


a) What is the difference between database schema and database state?
The database schema changes very infrequently. The database state changes every time the database is
updated.

b) Describe the three schema architecture?

c) What is the difference between a key and super-key?


A super-key can have redundant attributes, so a more useful concept is that of a KEY which has no
redundancy Key satisfied two constrains:
a. Two distinct tuple in any state of the relation cannot have identical values for the attributes in the
key
b. It is a minimal super-key

Question 04 [2+2+2+2 points]: Consider the database shown in the figure 5.6. Write down the queries to perform
the following operation in basic SQL Syntax. (You can use any SQL operation but syntax should be correct)
(CLO3)
a) Retrieve the names of all employees in department 5 who work more than 10 hours on the ‘ProductX’
project.
SELECT LNAME, FNAME
FROM EMPLOYEE, WORKS_ON, PROJECT
WHERE DNO=5 AND SSN=ESSN AND PNO=PNUMBER AND PNAME='ProductX' AND
HOURS>10

b) For each department that has more than five employees, retrieve the department number and the
number of its employees who are making more than $40,000.

SELECT Dnumber, COUNT (*)


FROM DEPARTMENT, EMPLOYEE
WHERE Dnumber=Dno AND Salary>40000 AND
( SELECT Dno
FROM EMPLOYEE
GROUP BY Dno
HAVING COUNT (*) > 5)

c) Retrieve the names of all employees who work in the department that has the employee with the
highest salary among all employees.

SELECT LNAME FROM EMPLOYEE WHERE DNO =


( SELECT DNO FROM EMPLOYEE WHERE SALARY =
( SELECT MAX(SALARY) FROM EMPLOYEE) )

d) Create a view that has the employee name, supervisor name, and employee salary for each employee
who works in the ‘Research’ department.

CREATE VIEW RESEARCH_EMPLOYEE_INFO (Lname,Fname,Supervisor,Salary) AS SELECT


E.Lname,E.Fname,S.Lname,E.Salary FROM EMPLOYEE E, EMPLOYEE S, DEPARTMENT D
WHERE Dname='Research' AND D.Dnumber=E.Dno AND E.Super_ssn=S.Ssn;

Question 5 [2+2+2 points]: Consider a database with the following schema: (CLO4)

 Person ( name, age, gender )


 Frequents ( name, ShopName )
 Eats ( name, pizza )
 Serves (ShopName, pizza, price )

Write relational algebra expressions for the following queries.


a) Find all ShopNames frequented by at least one person under the age of 18.

) )

b) Find the names of all females who eat either mushroom or pepperoni pizza (or both).

c) Find all ShopNames that serve at least one pizza that ‘Amy’ eats for less than $10.00.

) ))

Das könnte Ihnen auch gefallen