Lab Programs
Lab Programs
sname varchar(25),
rating number(2),
age float
);
day date
);
create table boats
bname varchar(25),
colour varchar(10)
);
DESCRIBE QUERY
10. Find the names of sailors 'Who have reserved boat number
103.
12. Find the names of sailors who have reserved a green boat.
13. Find the names of sailors who have reserved red boat 0r a
green boat.
16. Find the names of sailors who have Reserved at least one boat.
17. Find the ages of sailors whose name begins and ends with B and
has at least three characters.
19. Find the sids of sailors who have reserved a red or a green
boat.
UPDATE COMMANDS
20. Update all the sailors so they have a new rate of 19%.
22. Delete all the sailors, then decide it was not a good idea and to
rollback.
select sname, age from sailors where age = (select max(age) from
sailors);
27. Find the total number of sailors with age greater than 20.
29. Find the names of sailors who are older than the oldest sailor
with a rating of 10.
select sname from sailors where age > (select max (age) from sailors
where rating =10);
31. Find the age of the youngest sailor for each group.
34. Find the age of the youngest sailor who is eligible to vote (i.e.,
is at least 18 years old) for each rating level with at least two
such sailors.
36. For each red boat, find the number of reservations for this
boat.
37. Find those ratings for which the average age of sailors is the
minimum overall rating.
38. Find the names of sailors who have reserved a red or a green
boat(using UNION).
39. Find the names of sailors who have reserved both a red and a
green boat.
40. Find the sids of all sailors who have reserved red boats but not
green boats.
41. Find all sids of sailor who have a rating of 10 or reserved boat
104.
select sid from sailors where rating=10 union select sid from
reserves r where bid=104;
NESTED QUIRES
42. Find the names of sailors Who have reserved boat number 103.
select sname from sailors where sid in(select sid from reserves
where bid=103);
43. Find the names of sailors who have reserved a red boat.
select sname from sailors where sid in(select sid from reserves
where bid in(select bid from boats where colour=’Red’));
44. Find the names of sailors who have not reserved a red boat.
select sname from sailors where sid in(select sid from reserves
minus (select sid from reserves where bid in(select bid from boats
where colour=’Red’)));
SET-COMPARISON OPERATORS
45. Find sailors whose rating is better than some sailor called
Horatio.
select s1.sname, s1.rating from sailors s1 where s1.rating > all (select
s2.rating from sailors s2 where s2.sname='Horatio');
46. Find sailors whose rating is better than every sailor called
Horatio.
select s.sid from sailors s where s.rating > = all (select s2.rating
from sailors s2);
48. Find the names of sailors who have reserved both a red and a
green boat.
49. Find the names of sailors who have reserved all boat.
select * from sailors s where not exists(select * from boats b where
not exists(select * from reserves r where r.sid=s.sid and
r.bid=b.bid));
VIEW
CREATION OF TYPE
HomePhone VARCHAR2(30),
fax VARCHAR2(20)
email VARCHAR(30)
);
57. Create a table called New_sailors with all columns as the sailors
table and add a new column using this type for storing sailors
contact details.
sname varchar(25),
rating number(2),
age float,
s_phoneno contact_type
);
58. Write a DML script for adding in two new sailors including some
personal contact details.