Database Management Practical File
Database Management Practical File
b) Find names of sailors who’ve reserved a red or a green boat in the month of March.
d) Find sid of sailors who have not reserved a boat after Jan 2020.
e) Find sailors whose rating is greater than that of all the sailors named “Ajay”
h) Find the age of the youngest sailor for each rating with at least 2 such sailors
TABLES
create table sailors( sid int primary key,
sname varchar(256),
rating int,
dob date);
VALUES
insert into sailors values(100,’rahul’,98,’2000-05-23’);
insert into sailors values(101,’ravi’,98,’1995-05-23’);
insert into sailors values(102,’vikas’,32,’1990-05-23’);
insert into sailors values(103,’aditya’,32,’1996-05-23’);
insert into sailors values(104,’ajay’,40,’1994-10-25’);
RESERVES
insert into reserves values (100,1000,’2020-03-25’);
insert into reserves values (101,1001,’2019-04-25’);
insert into reserves values (100,1001,’2019-04-30’);
insert into reserves values (103,1002,’2020-04-30’);
insert into reserves values (103,1003,’2020-06-30’);
insert into reserves values (101,1000,’2020-05-24’);
insert into reserves values (102,1003,’2019-05-12’);
insert into reserves values (100,1002,’2019-06-13’);
insert into reserves values (100,1003,’2019-09-13’);
BOATS
insert into boats values (1000,’alpha’,’red’);
insert into boats values (1001,’bravo’,’green’);
insert into boats values (1002,’charlie’,’black’);
insert into boats values (1003,’delta’,’white’);
INTERSECTS
f) SELECT S.sname 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);
g) SELECT S.sname , TIMESTAMPDIFF(YEAR,dob,"2020-10-29") as age from SAILORS S where
S.dob IN
INVOICE TABLE
create table invoice(
inv_num int primary key,
prod_num int not null,
cust_num int not null,
inv_date date not null,
unit_sold int not null,
inv_amount int not null,
foreign key (prod_num) references product (prod_num),
foreign key (cust_num) references customer (cust_num),
check(unit_sold>0));
INSERTING VALUES
insert into invoice values (1,3,1,'2020-05-26',2,10000);
insert into invoice values (2,1,7,'2020-06-06',4,10000);
PRODUCT
create table product (prod_num int primary key,prod_name varchar(256) not null, price int
not null);
insert into product values(1,'phone',2500);
insert into product values(2,'radio',500);
insert into product values(3,'camera',5000);
insert into product values(4,'TV',3000);
a) SELECT concat (cust_fname,” “, cust_lname) as name FROM CUSTOMER
WHERE cust_balance=0;
d) LEFT JOIN
SELECT concat(cust_fname," ",cust_lname) as NAME,
i.inv_amount FROM customer c
LEFT JOIN invoice i
ON c.cust_num=i.cust_num;
RIGHT JOIN
SELECT concat(cust_fname," ",cust_lname) as NAME,
i.inv_amount FROM customer c
RIGHT JOIN invoice i
ON c.cust_num=i.cust_num;
FULL JOIN
JOB
create table job (Job_ID int primary key,Function varchar(256));
insert into job values(1000,'Works In Hardware');
insert into job values(1001,'Works In Security');
insert into job values(1002,’Works in Software');
insert into job values(1003,'Part Of HR');
insert into job values(1004,'Works In finanace team');
EMPLOYEE
create table employee(Employee_ID int,
Name varchar(256),
dob date,
Job_ID int,
Manager_ID int ,
Hire_Date date,
Salary int,
department_ID int,
Foreign key(Job_ID) references job(Job_ID),
Foreign key(Department_ID) references department (Department_ID));
insert into employee values (10,’ravi’,’2000-05-24’,1000,500,2000-09-23,10000,5);
insert into employee values (11,’aman’,’2005-05-24’,1003,500,2005-09-23,20000,2);
insert into employee values (12,’rohit’,’1990-05-24’,1002,501,2008-09-23,100000,3);
insert into employee values (13,’ram’,’1995-05-24’,1001,502,1990-09-30,40000,1);
insert into employee values (14,’yash’,’1981-09-24’,1004,502,2019-03-30,50000,4);
insert into employee values (15,’yash’,’1985-05-24’,1004,503,1981-10-24,60000,4);