You are on page 1of 4

SQL MAR 2004 sem V

Q1. a) Consider the following schema


BOOK (TITLE, AUTHORE, PUBLISHER, CATEGOPRY, PRICE)
DISTRIBUTOR (DISTID, DISTRIBUTOR, CITY,
DISCOUNT, CREDIT)
ORDER (ORDNO, TITLE, DISTID, QTY)
& write statement for the following (using sub queries)
i) Get the details of all books whose price is less then the average price of the books.
Select * From Book
Where Price< (select avg (Price) From Book)

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’)

b) Explain codd’s rules


Ans in page 65 of The Complete Ref. by James R. Groff.

c) List different data types used in SQL


Ans in page 79 of The Complete Ref. by James R. Groff.

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

d) Find all companies located in city in which AAA investment is located.


select company_name from company where city in (select
city from company where company_name like ‘AAA
investment’)

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)

C) Explain different architectures and the role of SQL in each.


Ans in page 37-41 of The Complete Ref. by James R.
Groff.

Q3. a) Write short note on (any two)


i) Phantom read
Ans in page 342 of The Complete Ref. by James R. Groff.
ii) Uncommitted data problem (dirty read)
Ans in page 339 of The Complete Ref. by James R. Groff.
iii) The function of check option in views give example
Ans in page 425 of The Complete Ref. by James R. Groff.

b) What are the different types of database structure explain in brief.


Ans in page 395 of The Complete Ref. by James R. Groff.

c) What are the basic privileges for tables and views


Ans in page 440 of The Complete Ref. by James R. Groff.

d) Write the statements for the following:


i) Create a table customer (cust_id, name, rep, credit) with cust_id as
primary key and rep as foreign key of salesreps table.
create table customers(cust_Id number(5),
name varchar2(20),rep number(5),
credit number(7),primary key(cust_Id),
constraint fkey1 foreign key(rep) references
sales_reps)

ii) insert a record into the customer table.


insert into customer values(1001,’aaa’,105,10000)

iv) delete a record from the customer table


delete from customer where cust_id=1001

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

b)what is explicit locking


Ans in page 352 of The Complete Ref. by James R. Groff.
c)Write the statement for the following :
i) grant the select , delete authority on Emp table to user ‘Jimmy’
Grant select, delete on emp to Jimmy

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

iv) remove all privilege on Emp table from user ‘Robert’


Revoke all privileges on emp from Robert

d) For the schema customers( custno , name , phone , credit)


a. define a view that displays the custno , name , phone
create view customerview(custno,name,phone)
As select custno,name,phone from customer

b. define a view that display all the columns & then insert a record
create view customerview (custno,name,phone,credit) as
select * from customer

Insert into customerview


values(1001,’aaa’,980001001,5000)
Q5 (a) Explain different types of views.
Ans in page 414 of The Complete Ref. by James R. Groff.

(b) What is an index? Why do we use it?


Ans in page 387 of The Complete Ref. by James R. Groff.

(c) What are locking parameters?


Ans in page 356 of The Complete Ref. by James R. Groff.

(d) What are the functions of DDL?


Ans in page 366 of The Complete Ref. by James R. Groff.

(e) What is locking? Explain different types of locking.


Ans in page 348 of The Complete Ref. by James R. Groff.

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.

(b) Explain the types of join.


Ans in page 175 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’

3) Get the average pay of an employee.


select avg(basic) from employee
or select avg(basic+hra-deduction-tax) from employee
4) Find the name of employee who gets the minimum basic pay.
select name from employee where basic=(select
min(basic) from employee)

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.

b) For the given table


RollNo Name Address phone
1 Ajay ghatkopar 21011
2 Sanjay kurla 42110
3 Ravi andheri
54212
i) update the phone number and address of rollno 2
update student set phone=554433 and address=’dadar’
Where rollno=2

ii) create an index on rollno in descending order


create index idx_roll on student(rollno desc)

c) Explain the operators ANY, ALL, EXISTS with examples.


Ans in page 228 of The Complete Ref. by James R. Groff.

d) What are primary key and foreign key


Ans in page 61,62 of The Complete Ref. by James R. Groff.

e) What are the types of search conditions.


Ans in page 110 of The Complete Ref. by James R. Groff.

---------------

You might also like