Practicalfile Dbms
Practicalfile Dbms
Inserting data
insert into Boats values (101, 'The Wind Ranger', 'Black'); insert into
Boats values (102, 'Seas the Day', 'Green'); insert into Boats values
(103, 'Jolly Rancher', 'Black'); insert into Boats values (104,
'Buoyant Buoy', 'Blue'); insert into Boats values (105, 'Serendipity',
'DarkBlue'); insert into Boats values (106, 'Aqua Life', 'Black');
insert into Boats values (107, 'Mizu Boto', 'Orange'); insert into
Boats values (108, 'The Prawn Star', 'Black');
b) Find names of sailors who’ve reserved a Red or a orange boat in the month of
March.
d) Find sid of sailors who have not reserved a boat after Jan 2018.
e) Find sailors whose rating is greater than that of all the sailors named “John”.
h) Find the age of the youngest sailor for each rating with at least 2 such sailors
RELATIONAL ALGEBRA
9
1
Write SQL queries and relational algebraic expression for the following
insert into customer value(203 , 'Daniel' , 'Radchiffe' , 5000);insert into customer value(321 , 'Emma' , 'Watson' , 8000);
insert into customer value(69 , 'Shrey' , 'Aggrawal' , 40000); insert
into customer value(4 , 'Rupert' , 'Grint' , 10000); insert into
customer value(56 , 'Alan' , 'Rickman' , 9000); insert into customer
value(439 , 'Tom' , 'Felton' , 12000); insert into customer value(908 ,
'Evanna' , 'Lynch' , 20000); insert into customer value(108 , 'Bonnie' ,
'Wright' , 50000); insert into customer value(72 , 'Loren' , 'Allred' ,
5000); insert into customer value(11 , 'Sasha' ,'Sloan' , 130000);
10
insert into product value(2, 'Razer Blade Stealth 14', 130000); insert into
product value(3, 'Macbook Pro 14 (2021)', 200000); insert into product
value(4, 'HP Spectre X360', 170000);
insert into product value(5, 'Apple Microfiber Cloth', 2000);
delimiter $$
create trigger check_age before insert on invoice for
each row
Update customer c
Set c.cust_balance = c.cust_balance + new.invoice_amount Where
c.cust_num = new.cust_num;
Select cust_fname ,cust_lname , cust_balance from customer;
12
i) Left Join
select customer.cust_num ,cust_fname , cust_lname , invoice_amount ,invoice_date from customer
left join invoice
on customer.cust_num = invoice.cust_num;
14
F) As soon as customer balance becomes greater than Rs. 100,000, copy the customer_num in
new table called ”GOLD_CUSTOMER”
Q3)
DEPARTMENT(Department_ID, Name, Location_ID) JOB (Job_ID ,
Function )
EMPLOYEE (Employee_ID, name, DOB, Job_ID , Manager_ID, Hire_Date, Salary,
department_id)
Inserting data
insert into department value(01 , 'Research' , 'Ghaziabad'); insert into
department value(02 , 'Accounting' , 'Delhi'); insert into department
value(03 , 'Development' , 'Gurgaon');
insert into department value(04 , 'Human resource management' , 'Gurgaon'); insert into
department value(05 , 'Sales' , 'Faridabad');
insert into department value(06 , 'Marketing' , 'Delhi'); insert into
department value(07 , 'Designing' , 'Sonipat'); insert into department
value(08 , 'Operations' , 'Faridabad');
-- emp_id , name , dob , job_id ,hire_date , manager , salary , departement_id insert into
employee value(1001 , 'Rachel Shroff' ,'1995-09-08' , 105,
'2018-03-06' ,800 , 50000 , 05);
insert into employee value(1002 , 'Nikita Adani' ,'1990-05-12' , 107 , '2013-09-
24', 815 , 100000, 06);
insert into employee value(1003 , 'Arshpreet Singh' ,'1992-05-15' , 102 , '2017-11-03'
,813 , 45000, 08);
insert into employee value(1004 , 'Shreyas Srivastava' ,'1991-10-22' , 106 , '2009-12-18'
,807 , 75000 , 01);
insert into employee value(1005 , 'Amit Trivedi' ,'1988-10-12' , 108 , '2017-03-
21' ,809 , 82000 , 04);
insert into employee value(1006 , 'Sunil Kumar' ,'1989-10-15' , 103 , '2016-04-
15' ,808 , 65000 , 03);
insert into employee value(1007 , 'Dinesh Singh' ,'1986-01-21' , 101 , '2014-03-22'
,813 , 90000 , 07);
insert into employee value(1008 , 'Vinod Kumar' ,'1990-01-12' , 104 , '2011-07-01'
,802 , 55000 , 02);
insert into employee value(1009 , 'Vishwajeet Jindal' ,'1988-10-08' , 103 , '2016-09-15'
,808 , 60000 , 03);
insert into employee value(1010 , 'Arundhati Roy' ,'1992-10-26' , 107 , '2015-08-14'
,815 , 120000 , 06);
11
from b.emp_delhi;
f) Write a trigger to ensure that no employee of age less than 25 can be inserted in the
database
delimiter $$
create trigger verify_age before insert on employee for each
row
begin
if new.dob > '1995-01-01' then signal
sqlstate '45000'
set message_text = 'error:
age must be atleast 25 years!'; end if;
end;
21
RELATIONAL ALGEBRA