You are on page 1of 27

CE246 DATABASE MANAGEMENT 20CE158

SYSTEM Pratham Patel

Faculty of Technology and Engineering


U & P U. Patel Department of Computer Engineering
Date: 03 / 02 / 2022

Practical List
Academic Year : 2021-22 Semester : 4
Course code : CE246 Course name : DATABASE MANAGEMENT
SYSTEM

Note: Practical List is for Students. We need to cover concept require to implement respective
practical.

Sr.
No. Practical 1
1. To study DDL-create and DML-insert commands
Write the following simple SQL Queries on the University
Dataset –
1. Find the names of all the students whose total credits
are greater than 100
2. Find the course id and grades of all courses taken by
any student named 'Tanaka'
3. Find the ID and name of instructors who have taught a
course in the Comp. Sci. department, even if they are
themselves not from the Comp. Sci. department. To
test this query, make sure you add appropriate data,
and include the corresponding insert statements along
with your query.
Find the courses which are offered in both 'Fall' and 'Spring' semester
(not necessarily in the same year).

Page 1 of 6
CE246 DATABASE MANAGEMENT 20CE158
SYSTEM Pratham Patel

MY QUERIES :-

OUTPUT OF QUERIES IN QUESTION:-

QUERY 1:

Page 2 of 6
CE246 DATABASE MANAGEMENT 20CE158
SYSTEM Pratham Patel

QUERY 2

Page 3 of 6
CE246 DATABASE MANAGEMENT 20CE158
SYSTEM Pratham Patel

QUERY 3

Page 4 of 6
CE246 DATABASE MANAGEMENT 20CE158
SYSTEM Pratham Patel

Page 5 of 6
CE246 DATABASE MANAGEMENT 20CE158
SYSTEM Pratham Patel

Page 6 of 6
CE246 DATABASE MANAGEMENT 20CE158
SYSTEM Pratham Patel

Faculty of Technology and Engineering


U & P U. Patel Department of Computer Engineering
Date: 20 / 1 / 2022

Practical List
Academic Year : 2021-22 Semester : 4
Course code : CE246 Course name : DATABASE MANAGEMENT
SYSTEM

Note: Practical List is for Students. We need to cover concept require to implement respective
practical.

Sr.
No. Practical 2
2. To study DDL-create and DML-insert commands with
constraints
Write the following simple SQL Queries on the University
Schema Railway Schema - Bottom Up Approach
1. Find pairs of stations (station codes) that have a track
(direct connection) with distance less than 20Kms
between them.
2. Find the IDs of all the trains which have a stop at
THANE
3. Find the names of all trains that start at MUMBAI.
4. List all the stations in order of visit by the train 'CSTAMR_LOCAL'.
5. Find the name of the trains which have stop at Thane,
before the 6th station in the route of the train.

Home Assignment – Any Relational schema design – Top Down


Approach

Page 1 of 5
CE246 DATABASE MANAGEMENT 20CE158
SYSTEM Pratham Patel

MY QUERIES :-
drop table trainhalts;
drop table train;
drop table track;
drop table station;

--This table contains one row for every halt of a train.


-- id : id of the train
-- seqno : the halt number. Assume that the starting station has seqno
as 0
-- stcode : station code of this halt
-- timein : time at which the train arrives at this station. (will be
null for the starting station of a train)
-- timeout: time at which the train departs this station. (will be null
for the terminating station of a train)
-- If a train passes through a station without stopping, then there will
be an entry with timein = timeout.

create table trainhalts


(id varchar(5) ,
seqno integer ,
stcode varchar(10),
timein varchar(5) ,
timeout varchar(5) ,
primary key (id,seqno) );

-- This table stores the distances between directly connected stations


stcode1 and stcode2.
-- Assume that this represents a directed track. i.e, for two stations A
and B, there will be
-- an entry corresponding to (A, B, distance) and another for (B,A,
distance).
create table track
(stcode1 varchar(5) ,
stcode2 varchar(5),
distance integer ,
primary key (stcode1,stcode2) );

create table station


(stcode varchar(5),
name varchar(20),
primary key (stcode));

create table train


(id varchar(5) ,
name varchar(20),
primary key (id) );

insert into station values ('CST' ,'MUMBAI');

Page 2 of 5
CE246 DATABASE MANAGEMENT 20CE158
SYSTEM Pratham Patel

insert into station values ('BYC' ,'BYCULLA');


insert into station values ('DR' ,'DADAR');
insert into station values ('KRL' ,'KURLA');
insert into station values ('GPR' ,'GHATKOPAR');
insert into station values ('TNA' ,'THANE');
insert into station values ('DL' ,'DOMBIVALI');
insert into station values ('AMR' , 'AMBARNATH');
insert into station values ('KYN' ,'KALYAN');
insert into station values ('KSR' ,'KASARA');
insert into train values ('KP11' ,'CST-KYN');
insert into train values ('KP11L' ,'CST-KYN_LOCAL');
insert into train values ('T129' ,'CST-TNA_LOCAL');
insert into train values ('A63' ,'CST-DL_LOCAL');
insert into train values ('K101' ,'CST-KYN_LOCAL');
insert into train values ('N27' ,'CST-TNA_LOCAL');
insert into train values ('S33' ,'CST-KGR_LOCAL');
insert into train values ('A65' ,'CST-AMR_LOCAL');
insert into track values ('CST' ,'BYC', 5);
insert into track values ('CST' ,'DR', 9);
insert into track values ('CST' ,'KRL', 16);
insert into track values ('CST' ,'GPR', 20);
insert into track values ('CST' ,'TNA', 34);
insert into track values ('CST' ,'DL', 49);
insert into track values ('CST' ,'KYN', 54);
insert into track values ('CST' ,'KSR', 77);
insert into track values ('CST' ,'AMR', 65);
insert into track values ('BYC' ,'DR', 4);
insert into track values ('BYC' ,'KRL', 11);
insert into track values ('GRP' ,'TNA', 14);
insert into track values ('DR' ,'TNA', 25);
insert into track values ('KRL' ,'KYN', 38);
insert into track values ('TNA' ,'KYN', 20);
insert into track values ('TNA' ,'KSR', 43);
insert into trainhalts values ('KP11' , 0 , 'CST' , NULL, '20.23');
insert into trainhalts values ('KP11' , 1 , 'BYC' , '20.31', '20.32');
insert into trainhalts values ('KP11' , 2 , 'DR' , '20.41', '20.42');
insert into trainhalts values ('KP11' , 3 , 'GPR' , '20.52', '20.53');
insert into trainhalts values ('KP11' , 4 , 'GPR' , '20.52', '20.53');
insert into trainhalts values ('KP11' , 5 , 'DR' , '20.41', '20.42');
insert into trainhalts values ('KP11' , 6 , 'GPR' , '20.58', '20.59');
insert into trainhalts values ('KP11' , 7 , 'TNA' , '21.21', '21.22');
insert into trainhalts values ('KP11' , 8 , 'DL' , '21.45', '21.46');
insert into trainhalts values ('KP11' , 9 , 'KYN' , '21.54', NULL);
insert into trainhalts values ('A65' , 0 , 'CST' , NULL , '20.52');
insert into trainhalts values ('A65' , 1 , 'BYC' , '21.00' , '21.01');
insert into trainhalts values ('A65' , 2 , 'DR' , '21.10' , '21.11');
insert into trainhalts values ('A65' , 3 , 'KRL' , '21.22' , '21.23');
insert into trainhalts values ('A65' , 4 , 'GPR' , '21.28' , '21.29');
insert into trainhalts values ('A65' , 5 , 'TNA' , '21.49' , '21.50');
insert into trainhalts values ('A65' , 6 , 'DL' , '22.13' , '22.14');
insert into trainhalts values ('A65' , 7 , 'KYN' , '22.22' , '22.23');
insert into trainhalts values ('A65' , 8 , 'AMR' , '22.36' , NULL);

Page 3 of 5
CE246 DATABASE MANAGEMENT 20CE158
SYSTEM Pratham Patel

OUTPUT OF QUERIES IN QUESTION:-

QUERY 1

QUERY 2

Page 4 of 5
CE246 DATABASE MANAGEMENT 20CE158
SYSTEM Pratham Patel

QUERY 3

QUERY 4

QUERY 5

Page 5 of 5
CE246 DATABASE MANAGEMENT 20CE158
SYSTEM Pratham Patel

Faculty of Technology and Engineering


U & P U. Patel Department of Computer Engineering
Date: 20 / 1 / 2022

Practical List
Academic Year : 2021-22 Semester : 4
Course code : CE246 Course name : DATABASE MANAGEMENT
SYSTEM

Note: Practical List is for Students. We need to cover concept require to implement respective
practical.

Sr.
No. Practical 3
3. To study various options of like predicate and some Built in Functions
Create table job (job_id, job_title, min_sal, max_sal)
Create table employee (emp_no, emp_name, emp_sal,
emp_comm, dept_no)
Create table deposit (a_no,cname,bname,amount,a_date).
Create table borrow (loanno,cname,bname,amount).
Perform following queries
1. Retrieve all data from employee, jobs and deposit.
2. Give details of account no. And deposited rupees of customers having account
opened between dates 01-01-06 and 25-07-06.
3. Display all jobs with minimum salary is greater than 4000.
4. Display name and salary of employee whose department no is 20. Give alias name
to name of employee.
5. Display employee no,name and department details of those employee whose
department lies in(10,20).
6. Display the non-null values of employee’s commission.
7. Display name of customer along with its account no (both column should be
displayed as one) whose amount is not equal to 8000 Rs.
8. Display the content of job details with minimum salary either 2000 or 4000.
Page 1 of 16
CE246 DATABASE MANAGEMENT 20CE158
SYSTEM Pratham Patel

To study various options of like predicate


9. Display all employee whose name start with ‘a’ and third character is ‘a’.
10. Display name, number and salary of those employees whose name is 5 characters
long and first three characters are ‘ani’.
11. Display all information of employee whose second character of name is either
‘m’ or ‘n’.
12. Find the list of all customer name whose branch is in ‘andheri’ or ‘dadar’ or
‘virar’.
13. Display the job name whose first three character in job id field is ‘fi_’.
14. Display the title/name of job whose last three character are ‘_mgr’ and there
maximum salary is greater than rs 12000.
15. Display the non-null values of employees and also employee name second
character should be ‘n’ and string should be 5 character long.
16. Display the null values of employee and also employee name’s third character
should be ‘a’.
17. What will be output if you are giving like predicate as ‘%\_%’ escape ‘\’ Select *
from job where job_id like ‘%\_%’ escape ‘\’

MY QUERIES :-
Create table tbl_Job (job_id varchar(20), job_title varchar(20), min_sal int, max_sal int);
Create table tbl_Employee (emp_no int, emp_name varchar(30), emp_sal int,
emp_commission varchar(30), dept_no int);
Create table tbl_Deposit (account_no varchar(30),customer_name
varchar(30),branch_name varchar(30),amount int,account_date date);
Create table tbl_Borrow (loanno varchar(30),customer_name varchar(30),branch_name
varchar(30),amount int);

insert into tbl_Job values('200','SalesManager',10000,40000);


insert into tbl_Job values('201','Cashier',3000,25000);
insert into tbl_Job values('202','JuniorManager',9500,27000);
insert into tbl_Job values('203','Clark',2000,19000);
insert into tbl_Job values('204','Director',25000,130000);
insert into tbl_Job values('205','BankManager',17000,80000);
insert into tbl_Job values('206','LoanOffcier',4000,38000);

insert into tbl_Employee values(2001,'Sujal',12500,1500,10);


insert into tbl_Employee values(2002,'Krish',15000,null,11);
insert into tbl_Employee values(2003,'Tushar',13000,3000,20);
insert into tbl_Employee values(2004,'Harsh',25000,6000,12);
insert into tbl_Employee values(2005,'Sejal',14000,3200,17);
insert into tbl_Employee values(2006,'Dhruv',16000,2100,17);

Page 2 of 16
CE246 DATABASE MANAGEMENT 20CE158
SYSTEM Pratham Patel

insert into tbl_Employee values(2007,'Hetvi',19500,null,20);


insert into tbl_Employee values(2008,'Rohan',70000,12500,18);
insert into tbl_Employee values(2009,'Isha',37000,null,10);
insert into tbl_Employee values(2010,'Pragnesh',24000,6500,10);
insert into tbl_Employee values(2011,'Darshan',16000,null,15);
insert into tbl_Employee values(2012,'Om',9500,5000,16);

insert into tbl_Deposit values('AC0010','Harun','andheri',65000,to_date('2-10-16',’DD-MM-


YY'));
insert into tbl_Deposit values('AC0011','Suresh','virar',200000, to_date ('03-11-17',’DD-MM-
YY'));
insert into tbl_Deposit values('AC0012','Nila','andheri',13000, to_date ('17-01-20',’DD-MM-
YY'));
insert into tbl_Deposit values('AC0035','Palak','dadar',12000, to_date ('24-06-15',’DD-MM-
YY'));
insert into tbl_Deposit values('AC0014','Parimal','dadar',26000, to_date ('07-11-19',’DD-MM-
YY'));
insert into tbl_Deposit values('AC0045','Kruvil','surat',4500, to_date ('10-02-19',’DD-MM-
YY'));
insert into tbl_Deposit values('AC0016','Sakshi','surat',1250, to_date ('03-12-19',’DD-MM-
YY'));
insert into tbl_Deposit values('AC0017','Darshil','baroda',3800, to_date ('29-11-17',’DD-MM-
YY'));
insert into tbl_Deposit values('AC0018','Zeel','anand',7450, to_date ('09-10-17',’DD-MM-
YY'));
insert into tbl_Deposit values('AC0059','Hemil','delhi',4750, to_date ('28-09-15',’DD-MM-
YY'));
insert into tbl_Deposit values('AC0020','Raj','mumbai',8430, to_date ('17-12-17',’DD-MM-
YY'));
insert into tbl_Deposit values('AC0029','Rajan','ahmedabad',2300, to_date ('21-08-18',’DD-
MM-YY'));
insert into tbl_Deposit values('AC0022','Dishant','virar',122800, to_date ('01-06-06',’DD-
MM-YY'));
insert into tbl_Deposit values('AC0026','Deven','baroda',14000, to_date ('02-05-03',’DD-
MM-YY'));
insert into tbl_Deposit values('AC0030','Pratham','virar',18500, to_date ('29-04-06',’DD-
MM-YY'));

insert into tbl_Borrow values('BID101','Harun',’ andheri’,20000);


insert into tbl_Borrow values('BID102','Suresh',’ virar’,250000);
insert into tbl_Borrow values('BID104','Nila',’ andheri’,230000);
insert into tbl_Borrow values('BID107','Palak',’dadar’,290000);
insert into tbl_Borrow values('BID127','Parimal',’dadar’,45000);
insert into tbl_Borrow values('BID122','Kruvil',’surat’,47000);
insert into tbl_Borrow values('BID129','Darshil',’baroda’,1500);
Page 3 of 16
CE246 DATABASE MANAGEMENT 20CE158
SYSTEM Pratham Patel

insert into tbl_Borrow values('BID135','Sakshi',’surat’,34000);


insert into tbl_Borrow values('BID138','Rajan',’ ahmedabad’,11000);
insert into tbl_Borrow values('BID143','Zeel',’ anand’,99000);
insert into tbl_Borrow values('BID153','Pratham',’ virar’,110000);
insert into tbl_Borrow values('BID172','Deven',’ baroda’,550000);

Page 4 of 16
CE246 DATABASE MANAGEMENT 20CE158
SYSTEM Pratham Patel

Page 5 of 16
CE246 DATABASE MANAGEMENT 20CE158
SYSTEM Pratham Patel

Page 6 of 16
CE246 DATABASE MANAGEMENT 20CE158
SYSTEM Pratham Patel

OUTPUT OF QUERIES IN QUESTION:-

QUERY 1

Page 7 of 16
CE246 DATABASE MANAGEMENT 20CE158
SYSTEM Pratham Patel

Page 8 of 16
CE246 DATABASE MANAGEMENT 20CE158
SYSTEM Pratham Patel

Page 9 of 16
CE246 DATABASE MANAGEMENT 20CE158
SYSTEM Pratham Patel

QUERY 2

Page 10 of 16
CE246 DATABASE MANAGEMENT 20CE158
SYSTEM Pratham Patel

QUERY 3

QUERY 4

QUERY 5

Page 11 of 16
CE246 DATABASE MANAGEMENT 20CE158
SYSTEM Pratham Patel

QUERY 6

QUERY 7

Page 12 of 16
CE246 DATABASE MANAGEMENT 20CE158
SYSTEM Pratham Patel

QUERY 8

QUERY 9

QUERY 10

Page 13 of 16
CE246 DATABASE MANAGEMENT 20CE158
SYSTEM Pratham Patel

QUERY 11

QUERY 12

QUERY 13

Page 14 of 16
CE246 DATABASE MANAGEMENT 20CE158
SYSTEM Pratham Patel

QUERY 14

QUERY 15

QUERY 16

QUERY 17

Page 15 of 16
CE246 DATABASE MANAGEMENT 20CE158
SYSTEM Pratham Patel

Page 16 of 16

You might also like