Ar Dbs Final
Ar Dbs Final
Ar Dbs Final
Practical File
CBCPC05
e) Find sailors whose rating is greater than that of all thesailors named
“John”
h) Find the age of the youngestsailorfor each rating withat least 2 such
sailors
RELATIONAL ALGEBRA FOR Q1
Ques 2) Consider the following relational schema:
CUSTOMER (cust_num, cust_lname , cust_fname, cust_balance);
PRODUCT (prod_num, prod_name, price)
INVOICE (inv_num, prod_num, cust_num, inv_date ,unit_sold, inv_amount);
Write SQL queries and relational algebraic expression for the following
create table customer ( cust_num int primary key,cust_fname varchar(20),
cust_lname varchar(20), cust_balance int );
create table product ( prod_num int primary key,prod_name varchar(30), price
int );
create table invoice( invoice_num int, prod_num int , cust_numint not
null,invoice_date date, unit_sold int, invoice_amountint, primary key
(invoice_num ,prod_num , cust_num , invoice_date), foreign key (cust_num)
references customer(cust_num)on delete cascade, foreign key (prod_num)
references product(prod_num)on delete cascade );
insert into customer values(11 , 'Rohan' , 'Singh' , 5000);insertinto customer
values(12 , 'Ronak' , 'Godara' , 8000);
insert into customer values(13 , 'Atharav' , 'Mahajan' ,40000); insertinto
customer values(14 , 'Ishan' , 'Mehta' , 10000);
insert into customer values(15 , 'Virat' , 'Kohli' , 9000); insert into customer
values(16 , 'Tanishq' , 'Mehta' ,12000);
insert into customer values(17 , 'Justin' , 'Timberlake' ,20000);
insertintocustomer values(18,'Taylor','Swift',50000);
insert into customer values(19, 'Rock' , 'Bottom' , 5000);insert into customer
values(20 , 'Tyler' ,'woods' , 0);
insert into product values(101, 'Register', 30);
insert into product values(102, 'Pen', 10);
insert into product values(103, 'Laptop', 50000);
insert into product values(104, 'Mouse', 1300);
insert into product values(105, 'Tablet', 25000);
insert into product values(106, 'Bag', 770);
insert into product values(107, 'Colours', 150);
insert into product values(108, 'Mobile', 18000);
insert into invoice values(1,'101' ,13 ,'2021-11-21' ,2 ,30);
insert into invoice values(2,'104' ,14 ,'2021-12-10' ,1 ,1300);
insert into invoice values(3,'102' ,11 ,'2015-10-12' ,1 ,40000);
insert into invoice values(4,'105' ,16 ,'2011-01-22' ,3 ,1400);
insert into invoice values(5,'106' ,13 ,'2021-05-19' ,2 ,1500);
insert into invoice values(6,'102' ,12 ,'2010-12-09' ,12 ,100);
insert into invoice values(7,'105' ,15 ,'2018-09-03' ,10 ,5000);
insert into invoice values(8,'108' ,16 ,'2019-10-22' ,2 ,1500);
insert into invoice values(9,'107' ,18 ,'2020-01-18' ,12 ,150);
insert into invoice values(10,'104' ,14 ,'2021-11-23' ,5 ,6000);
insert into invoice values(11,'103' ,12 ,'2017-10-13' ,2 ,75000);
insert into invoice values(12,'108' ,16 ,'2020-11-31' ,1 ,8000);
insert into invoice values(12,'108' ,17 ,'2020-11-23' ,1 ,8000);
a) Find the names of the customer who have purchasedno item. Set default
value of Cust_balance as 0 for such customers.
b) Write the trigger to update the CUST_BALANCE in theCUSTOMER table
when a new invoice record is entered for the customer.
c) Find the customers who have purchased more than three units of a
product in a day
d) Write a query to illustrate Left Outer, Right Outer and Full Outer Join.
left:
Right:
Full:
e) Count the number of products sold on each date
’
Q3) Consider the following relational schema :
DEPARTMENT(Department_ID, Name, Location_ID)
JOB (Job_ID , Function )
EMPLOYEE (Employee_ID, name, DOB, Job_ID , Manager_ID, Hire_Date,
Salary, department_id)
Answer the following queries using SQL and relational algebra: