2020UCM2333-DBMS Practical File
2020UCM2333-DBMS Practical File
2020UCM2333-DBMS Practical File
INSERTING VALUES
QUERIES
a)
select sname
from sailors
where sid in (select sid from reserves);
b)
select sname from
sailors where sid in ( select
r.sid
from boats b, reserves r where r.bid = b.bid AND
b.color = "red" and (select extract(month from
r.dt)="03") union
select r2.sid from boats b2, reserves r2 where
r2.bid = b2.bid AND b2.color = "green" and (select
extract(month from r2.dt)="03") );
c)
select distinct S1.sname from
sailors S1, reserves R1, boats B1,
reserves R2, boats B2
where S1.sid=R1.sid and R1.bid=B1.bid and
S1.sid=R2.sid and R2.bid=B2.bid and
B1.color="red" and B2.color="green";
d)
select sid
from sailors
where sid not in
(select sid from reserves
where dt>="2018-01-01");
e)
select sname
from sailors where rating > all (select rating from
sailors where sname="sagar");
f)
select sname from sailors where not exists
(select * from boats b where not exists ( select * from
reserves r where r.sid=s.sid AND
r.bid=b.bid));
g)
select sname,TIMESTAMPDIFF
(YEAR,date_of_birth,"2020-09-17") as age
from sailors
where date_of_birth <=all(select date_of_birth
from sailors);
Ques 2:-
Consider the following relational schema:
INSERTING VALUES
QUERIES
a)
select concat(cust_fname,” ”,cust_lname) as
name from customer
where cust_balance=0;
b).
create trigger upd_cust before
insert on invoice
for each row up[date customer c set
c.cust_balance=.c.cust_balance+inv_amount where
c.cust_num=new.cust_num;
c).
select cust_num,concat (cust_fname,” “ ,cust_lname)
from customer
where cust_num
in(select cust_num from invoice group by
cust_num,inv_date,prod_num having
sum(unit_sold)>3);
d).
select concat(c.cust_fname,c.cust_lname) as
name, i.inv_amount from customer c left join
invoice
on c.cust_numi.cust_num;
select concat(c.cust_fname,c.cust_lname) as
name, i.inv_amount from customer c right join
invoice
on c.cust_numi.cust_num;
select concat(c.cust_fname,c.cust_lname)
as name, i.inv_amount from customer c left
join invoice on
c.cust_num.cust_num; union
select concat(c.cust_fname,c.cust_lname) as
name, i.inv_amount from customer c right join
invoice
on c.cust_numi.cust_num;
e).
select inv_date,sum(unit_sold) as
total_daily_sales from invoice
group by inv_date;
f).
create table GOLD CUSTOMER(
cust_num int, cust_fname
varchar(50); cust_lname
varchar(50); primary
key(cust_num));
g).
alter table customer add
column cust_cust_dob date;
Ques 3:-
Consider the following relational schema:
);
Hire_Date date,
Salary int,
Department_ID varchar(5),
FOREIGN KEY (Job_ID)
REFERENCES JOB(Job_ID),
FOREIGN KEY (Department_ID)
REFERENCES DEPARTMENT(Department_ID)
);
INSERTING VALUES
INSERT INTO DEPARTMENT VALUES
QUERIES
a)
SELECT COUNT(Employee_ID)
FROM EMPLOYEE
WHERE Hire_Date >= "2015-03-01" AND
Hire_Date <= "2015-03-31";
(b)
SELECT *
FROM EMPLOYEE
GROUP BY Salary
ORDER BY Salary DESC LIMIT 1
(c)
SELECT SUM(Salary),
Department_ID FROM EMPLOYEE
GROUP BY Department_ID;
(d)
SELECT SUM(Salary),
Department_ID FROM EMPLOYEE
GROUP BY Department_ID ORDER
BY SUM(Salary) DESC LIMIT 1;
(e)
CREATE VIEW DELHI_EMPLOYEES AS
SELECT COUNT(Employee_ID)
FROM EMPLOYEE, DEPARTMENT
WHERE
(Location_ID="DEL01" OR Location_ID =
"DEL02") AND EMPLOYEE.Department_ID =
DEPARTMENT.Department_ID;
(f)