Professional Documents
Culture Documents
ii)Get the numbers of all distributors who are supplying the books whose author is
‘peterson’ (using nested sub queries)
Select Distributor From Distributor
Where DistID IN (Select DistID from Order Where Title like
( select Title from Book where Author like ’Peterson’))
iii) Get the details of all books whose price is grater than the average of the category
average.
select * from books where price > All(select avg(price)
from Book group by category)
or
select * from book where price >(Select avg(Select
avg(price) from book group by category)
iv) Get the details of all distributors who give more discount then the average discount
select * from distributor where discount > (select
avg(discount) from distributor)
v) Get the names of all distributors who are supplying the book titled ‘Software
Engineering’ to the book shop.
select distributor from Distributor where distID in (select
distID from orders where title like ‘Software Engineering’)
Q.2 a) Explain referential integrity & discuss the four update situations that can corrupt
the referential integrity.
Ans in page 299-300 of The Complete Ref. by James R.
Groff.
b) Study the following schema for employee_details database and write the queries.
Employee (employee_name , street, city)
Works (employee_name, company_name, salary)
Company (company_name, city)
Manages (employee_name, manager_name)
a) Find names, street address, city of all employee who work for AAA investment
and more than $10,000.
select e.* from Employee e, Works w
where e.employee_name= w.employee_name And
w.company_name=’AAA investment’ And Salary>10000
b) Find all employee in the data base who live in same city as in the companies
for which they are working.
select employee_name from Employee e, company c, works
w Where e.employee_name =w.employee_name and
c.company_name=w.company_name and e.city=c.city
c) Find all employee in the data base who live in same cities and on the same
streets as do their managers.
select distinct employee_name from employee e, (select
city, street from manager m, employee e where
e.employee_name=m.manager_name) f
Where e.city=f.city and e.street=f.street
e) Give all managers of AAA investment a 10% raise if the salary is less than
$100,000 .
update works set salary=salary*0.1 Where employee_name
in (select w.employe_name from works w,manager m where
m.manager_name=w.employee_name And company_name like
‘AAA investment’ And salary <10000)
Q4.a) what do you mean by data integrity . explain types of data integrity constraints
Ans in page 292 of The Complete Ref. by James R. Groff.
Hint: Primary key, Foreign key, Unique, Not null, Check
ii) grant select , insert authority with the capacity to grant those privilege
to other users on Emp table to user ‘Jimmy’
Grant select, insert on emp to Jimmy with grant
option
iii) revoke the insert privileges on Emp table from all users
Revoke insert on emp from public
b. define a view that display all the columns & then insert a record
create view customerview (custno,name,phone,credit) as
select * from customer
Q6. (a) Which are the four delete rules that can avoid the corruption of referential
integrity?
Ans in page 302 of The Complete Ref. by James R. Groff.
(c) For the given schema Employee(empno, name, dptid, basic, HRA, deductions,
tax). Write the statement for following queries:-
1) Get the number of employees in the department ‘D5’ and basic pay less than
10000
select count(empno) from employee where deptid=’D5’
and basic<10000
2) Find the total pay for all the employees in the department ‘D1’ .
select basic+hra-deduction-tax “total pay” from
employee where deptid=’D1’
5) Find the employees whose basic pay is greater than the average basic pay.
select name from employee where basic>(select
avg(basic) from employee)
6) Get the department ID , the average, maximum and minimum pay of all the
departments.
select deptid ,avg(basic),max(basic),min(basic) from
employee group by deptid
Q7. a) What is transaction. What are the functions of commit and rollback.
Ans in page 328 of The Complete Ref. by James R. Groff.
---------------