You are on page 1of 3

SET A

1. create table sailors(s_id int,s_name char(20),rating float,age


int,primary key(s_id));
create table boats(b_id int,b_name char(20),color
char(20),primary key(b_id));
create table reserves(s_id int,b_id int,day int,foreign
key(s_id) references sailors(s_id),foreign key(b_id) references
boats(b_id));

2. insert into sailors values (1,'sakshi',5,18),(2,'arun',4,45),


(3,'kushal',4,55),(4,'tanisha',3,59);
insert into boats values (101,'ship','blue'),
(102,'yacht','white'),(103,'cruise','pink'),(104,'raft','yellow');

insert into reserves values (2,102,10),(4,104,7),(1,101,6),


(3,101,4);

3. 1 - select s_name from sailors where age between 50 and 60;


2 - select b_name from boats where color = ‘blue’;
3 - select b_name from boats where b_id in(select b_id from
reference where s_id = '1');
4 - select avg(age) from sailors group by rating;
5 - select s_name from sailors where age > (select avg(age)
from sailors);

4. Write disadvantages of natural join?


SET B

1. create table customer(c_id int,c_name


char(20),annual_revenew int,primary key(c_id));

create table truck(truck_no int,driver_name


char(30),primary key(truck_no));

create table city(city_name char(30),population


int,primary key(city_name));

create table shipment(shipment_no int primary key,weight


int,truck_no int,destination char(90),c_id int, foreign
key(truck_no) references truck(truck_no),foreign
key(destination) references city(city_name),foreign key(c_id)
references customer(c_id));

2. insert into city values ( 'rajasthan',7000000) ,


('alwar',600000),('jaipur',800000),('kota',900000);
insert into truck values(6060,'vijay'),(7070,'ajay'),
(8080,'ramesh'),(9090,'satish');

insert into customer values(11,'sakshi',10000),


(12,'arun',20000),(13,'kushal',30000),(14,'tanisha',40000);

insert into shipment values(111,20,7070,’kota’,12),


(222,40,9090,'jaipur',13),(333,30,8080,'alwar',11),
(444,50,6060,'rajasthan',14);

3. 1 - select shipment_no from shipment where weight>20;


2 - select c_name from customer where annual_revenew
not in(10000,20000,30000);
3 - select avg(weight)from shipment;
4 - select shipment_no from shipment where truck_no
in(select truck_no from truck where driver_name= 'ramesh');

4. Write disadvantages of outer join?

Ans. There are two main limitations of OUTER JOINS in DB2.


 The WHERE clause of OUTER JOIN can only have ‘=’
relational operator. <,>, etc are not allowed in case of
OUTER JOIN of two or more tables. Also two or more
conditions in WHERE clause can only be used with AND
logical operator, other logical operators such as OR, NOT is
not allowed.
 The functions to handle NULL operators such as VALUE and
COALESCE could not be used with the OUTER JOINS.

You might also like