You are on page 1of 19

Faculty of Engineering & Technology

SubjectName : DBMS
Subject Code : 203105251
B.Tech CSE Year 2019-20 Semester 4th

Annexure No : 1
PRACTICAL:-1
Aim :- To study DDL-create and DML-insert commands.
(i) Create tables according to the following definition.
(1) Create Table Deposit (ACTNO NUMBER (4), CNAME VARCHAR2 (20), BNAME
VARCHAR2 (20), AMOUNT NUMBER (8, 2), ADATE DATE);

Column Name Data Type


ACTNO NUMBER (4)
CNAME VARCHAR2 (20)
BNAME VARCHAR2 (20)
AMOUNT NUMBER (8,2)
ADATE DATE

(2) Create Table Branch (BNAME VARCHAR2 (20), CITY VARCHAR2 (20));

Column Name Data Type


BNAME VARCHAR2 (20)
CITY VARCHAR2 (20)

(3) Create Table Customer (CNAME VARCHAR2 (20), CITY VARCHAR2 (20));

Column Name Data Type


CNAME VARCHAR2 (20)
CITY VARCHAR2 (20)

(4) Create Table Borrow (LOANNO NUMBER (4), CNAME VARCHAR2 (20), BNAME
VARCHAR2 (20), AMOUNT NUMBER (8, 2));

Column Name Data Type


LOANNO NUMBER (4)
CNAME VARCHAR2 (20)
BNAME VARCHAR2 (20)
AMOUNT NUMBER (20)

(ii) Insert the data as shown below.


Table 1: DEPOSIT
ACTNO CNAME BNAME AMOUNT ADATE
100 ANIL VRCE 10000.00 1-MAR-95
101 SUNIL AJNI 50000.00 4-JAN-96
102 MEHUL KAROLBAGH 6500.00 17-NOV-95
104 MADHURI CHANDI 5200.00 17-DEC-95
105 PRMOD M.G.ROAD 30000.00 27-MAR-96
106 SANDIP ANDHERI 2500.00 31-MAR-96

180303105313 Page No:- 1


Faculty of Engineering & Technology
SubjectName : DBMS
Subject Code : 203105251
B.Tech CSE Year 2019-20 Semester 4th

Annexure No : 2
107 SHIVANI VIRAR 10000.00 5-SEP-95
108 KRANTI NEHRU 50000.00 2-JUL-95
PLACE
109 MINU POWAI 70000.00 10-AUG-95

Table 2: BRANCH
BNAME CITY
VRCE NAGPUR
AJNI NAGPUR
KAROLIBAGH DELHI
CHANDI DELHI
DHARAMPETH NAGPUR
M.G.ROAD BANGLORE
ANDHERI BOMBAY
VIRAR BOMBAY
NEHRU_PLACE DELHI
POWAI BOMBAY

Table 3: CUSTOMER
CNAME CITY
ANIL CALCUTTA
SUNIL DELHI
MEHUL BARODA
MANDAR PATNA
MADHURI NAGPUR
PRMOD NAGPUR
SANDIP SURAT
SHIVANI BOMBAY
KRANTI BOMBAY
NAREN BOMBAY

Table 4: BORROW
LOANNO CNAME BNAME AMOUNT
201 ANIL VRCE 10000.00
206 MEHUL AJNI 50000.00
311 SUNIL DHARAMPETH 30000.00
321 MADHURI ANDHERI 20000.00
375 PRAMOD VIRAR 80000.00
481 KRANTI NEHRU_PLACE 30000.00

Solution :-
Description:-
Create:-
Syntax:-

180303105313 Page No:- 2


Faculty of Engineering & Technology
SubjectName : DBMS
Subject Code : 203105251
B.Tech CSE Year 2019-20 Semester 4th

Annexure No : 3
create table table_name(column_name datatype (size),..);
Create statement is used to create a newtable into Database.
Insert:-
Syntax:-
insert into table_name values (content,..);
Insert statement is used to insert a single record or multiple record into a table in Database.
Select:-
Syntax:-
select * from table_name;
Select statement is used to retrive records from one or more table in a Database.

(1) create table deposit (ACTNO NUMBER (4),CNAME VARCHAR2 (20),BNAME


VARCHAR2 (20),AMOUNT NUMBER (8, 2),ADATE DATE);

insert into deposit values(100,’ANI’,’VRCE’,10000.00,’1-MAR-95’);


insert into deposit values(101,’SUNIL’,’AJNI’,50000.00,’14-JAN-96’);
insert into deposit values(102,’MEHUL’,’KAROLBAGH’,6500.00,’17-NOV-95’);
insert into deposit values(104,’MADHURI’,’CHANDI’,5200.00,’17-DEC-95’);
insert into deposit values(105,’PRMOD’,’M.G.ROAD’,30000.00,’27-MAR-96’);
insert into deposit values(106,’SANDIP’,’ANDHERI’,2500.00,’31-MAR-96’);
insert into deposit values(107,’SHIVANI’,’VIRAR’,10000.00,’5-SEP-95’);
insert into deposit values(108,’KRANTI’,’NEHRU_PLACE’,50000.00,’2-JUL-95’);
insert into deposit values(109,'MINU’,’POWAI’,70000.00,’10-AUG-95’);

select *from deposit;

(2) create table branch (BNAME VARCHAR2 (20),CITY VARCHAR2 (20));

insert into branch values(‘VRCE’,’NAGPUR’);


insert into branch values(‘AJNI’,’NAGPUR’);
insert into branch values(‘KAROLBAGH’,’DELHI’);

180303105313 Page No:- 3


Faculty of Engineering & Technology
SubjectName : DBMS
Subject Code : 203105251
B.Tech CSE Year 2019-20 Semester 4th

Annexure No : 4
insert into branch values(‘CHANDI’,’DELHI’);
insert into branch values(‘DHARAMPETH’,’NAGPUR’);
insert into branch values(‘M.G.ROAD’,’BANGLORE’);
insert into branch values(‘ANDHERI’,’BOMBAY’);
insert into branch values(‘VIRAR’,’BOMBAY’);
insert into branch values(‘NEHRU_PLACE’,’DELHI’);
insert into branch values(‘POWAI’,’BOMBAY’);

select * from branch;

(3) create table customer(CNAME VARCHAR2 (20),CITY VARCHAR2 (20));

insert into customer values (‘ANIL’,’CALCUTTA’);


insert into customer values(‘SUNIL’,’DELHI’);
insert into customer values(‘MEHUL’,’BARODA’);
insert into customer values(‘MANDAR’,’PATNA’);
insert into customer values(‘MADHURI’,’NAGPUR’);
insert into customer values(‘PRAMOD’,’NAGPUR’);
insert into customer values(‘SANDIP’,’SURAT’);
insert into customer values(‘SHIVANI’,’BOMBAY’);
insert into customer values(‘KRANTI’,’BOMBAY’);
insert into customer values(‘NAREN’,’BOMABAY’);

select * from customer;

180303105313 Page No:- 4


Faculty of Engineering & Technology
SubjectName : DBMS
Subject Code : 203105251
B.Tech CSE Year 2019-20 Semester 4th

Annexure No : 5

(4) create table borrow(LOANNO NUMBER (4),CNAME VARCHAR2 (20),BNAME


VARCHAR2 (20),AMOUNT NUMBER (8, 2));

insert into borrow values(201,’ANIL’,’VRCE’,10000.00);


insert into borrow values(206,’MEHUL’,’AJNI’,50000.00);
insert into borrow values(311,’SUNIL’,’DHARAMPETH’,30000.00);
insert into borrow values(321,’MADHURI’,’ANDHERI’,20000.00);
insert into borrow values(375,’PRAMOD’,’VIRAR’,80000.00);
insert into borrow values(481,’KRANTI’,’NEHRU_PLACE’,30000.00);

select * from borrow;

(iii) From the above given tables perform the following queries:
(1) Describe deposit, branch.
Soln:-describe deposit;
describe branch;

180303105313 Page No:- 5


Faculty of Engineering & Technology
SubjectName : DBMS
Subject Code : 203105251
B.Tech CSE Year 2019-20 Semester 4th

Annexure No : 6

(2) Describe borrow, customers.


Soln:- describe borrow;
describe customer;

(3) List all data from table DEPOSIT.

Sol:-select * from deposit;

180303105313 Page No:- 6


Faculty of Engineering & Technology
SubjectName : DBMS
Subject Code : 203105251
B.Tech CSE Year 2019-20 Semester 4th

Annexure No : 7

(4) List all data from table BORROW.


Soln:-select * from borrow;

(5) List all data from table CUSTOMERS.


Soln:-select * from customer;

(6) List all data from table BRANCH.


Soln:-select * from branch;

180303105313 Page No:- 7


Faculty of Engineering & Technology
SubjectName : DBMS
Subject Code : 203105251
B.Tech CSE Year 2019-20 Semester 4th

Annexure No : 8

(7) Give name of depositors having amount greater than 10000.


Soln:- select cname from deposit where amount > 10000;

(8) Give name of customers who opened account after date ' 5-SEP-95’ .
Soln:- select cname from deposit where adate > ‘5-SEP-95’;

PRACTICAL:-2
Aim:-Create the below given table and insert the data accordingly.
(i) Create tables according to the following definition.
(1) Create Table job (job_id, job_title, min_sal, max_sal).

COLUMN NAME DATA TYPE


job_id Varchar2(10)

180303105313 Page No:- 8


Faculty of Engineering & Technology
SubjectName : DBMS
Subject Code : 203105251
B.Tech CSE Year 2019-20 Semester 4th

Annexure No : 9
job_title Varchar2(40)
min_sal Number(7,2)
max_sal Number(7,2)

(2) Create table employee (emp_no, emp_name, emp_sal, emp_comm, dept_no).

COLUMN NAME DATA TYPE


emp_no Number(4)
emp_name Varchar2(50)
emp_sal Number(7,2)
emp_comm Number(5,1)
dept_no Number(3)

(3) Create table deposit (a_no, cname, bname, amount, a_date).

COLUMN NAME DATA TYPE


a-no Varchar2(14)
Cname Varchar2(20)
Bname Varchar2(30)
Amount Number(9,2)
a-date Date

(4) Create table borrow (loanno, cname, bname, amount).

COLUMN NAME DATA TYPE


loan_no Number(7)
Cname Varchar2(30)
Bname Varchar2(30)
Amount Number(9,2)

(ii) Insert the data as shown below.


(1) Insert following values in the table job.

job_id job_name min_sal max_sal


IT_PROG Programmer 40000 100000
MK_MGR Marketing Manager 90000 150000
FI_MGR Finance Manager 82000 120000
FI_ACC Account 42000 90000
LEC Lecturer 6000 170000
COMP_OP Computer Operator 15000 30000

(2)Insert following values in the table employee.

emp-n emp_name emp_sal emp_comm dept_no


101 Smith 80000 120

180303105313 Page No:- 9


Faculty of Engineering & Technology
SubjectName : DBMS
Subject Code : 203105251
B.Tech CSE Year 2019-20 Semester 4th

Annexure No : 10
102 Snehal 160000 300 125
103 Adama 110000 0 120
104 Aman 300000 115
105 Anita 5000000 50000 110
106 Sneha 2400000 24500 110
107 Anamika 29075 130

(3) Insert following values in the table deposit.

A-no C_name Bname Amount Date


101 Anil Andheri 7000 1-Jan-16
102 Sunil Virar 5000 15-Jul-12
103 Jay Villeparle 6500 12-Mar-16
104 Vijay Andheri 8000 17-Sep-13
105 Keyur Dadar 7500 19-Nov-12
106 Mayor Borivali 5500 21-Dec-06

(4) Insert following values in the table borrow.


LOANNO CNAME BNAME AMOUNT
201 ANIL VRCE 10000.00
206 MEHUL AJNI 50000.00
311 SUNIL DHARAMPETH 30000.00
321 MADHURI ANDHERI 20000.00
375 PRAMOD VIRAR 80000.00
481 KRANTI NEHRU_PLACE 30000.00

Solution:-
(1) create table job(job_id varchar2(10),job_title varchar2 (40),min_sal number(7,2),max_sal
number(10,2));

insert into job values(‘IT_PROG’,’PROGRAMMER’,40000,1000000);


insert into job values(‘MK-MGR’,’MARKETING MANAGER’,90000,150000);
insert into job values(‘FI_MGR’,’FINANCE MANAGER’,82000,120000);
insert into job values(‘FI_ACC’,’ACCOUNT’,42000,90000);
insert into job values(‘LEC’,LECTURER’,6000,170000);
insert into job values(‘COMP_OP’,’COMPUTER OPERATOR’,15000,30000);

select * from job;

180303105313 Page No:- 10


Faculty of Engineering & Technology
SubjectName : DBMS
Subject Code : 203105251
B.Tech CSE Year 2019-20 Semester 4th

Annexure No : 11

(2) create table employee(emp_no number(4),emp_name varchar2(50),emp_sal


number(7,2), emp_comm (5,1),dept_no number(3));

insert into employee values(101,’SMITH’,80000,’’ ,120);


insert into employee values(102,’SNEHAL’,160000,300,125);
insert into employee values(103,’ADAMA’,110000,0,120);
insert into employee values(104,’AMAN’,300000,’’,115);
insert into employee values(105,’ANITA’,5000000,50000,110);
insert into employee values(106,’SNEHA’,24000000,24500,110);
insert into employee values(107,’ANAMIKA’,29075,’’,130);
select * from employee;

(3) craete table deposit (a_no number (4),cname varchar2(20) bname varchar2(30),amount
number(9,2),a_date DATE);

insert into deposit values(101,’ANIL’,’ANDHERI’,7000,’1-JAN-16’);


insert into deposit values(102,’SUNIL’,’VIRAR’,5000,’15-JUL-12’);
insert into deposit values(103,’JAY’,’VILLEAPARLE’,6500,’12-MAR-16’);
insert into deposit values(104,’VIJAY’,’ANHERI’,8000,’17-SEP-13’);
insert into deposit values(105,’KEYUR’,’DADAR’,7500,’19-NOV-12’);
insert into deposit values(106,’MAYOR’,’BORIVALI’,5500,’21-DEC-06’);

180303105313 Page No:- 11


Faculty of Engineering & Technology
SubjectName : DBMS
Subject Code : 203105251
B.Tech CSE Year 2019-20 Semester 4th

Annexure No : 12
select * from deposit;

(4) create table borrow(LOANNO NUMBER (4),CNAME VARCHAR2 (20),BNAME


VARCHAR2 (20),AMOUNT NUMBER (8, 2));

insert into borrow values(201,’ANIL’,’VRCE’,10000.00);


insert into borrow values(206,’MEHUL’,’AJNI’,50000.00);
insert into borrow values(311,’SUNIL’,’DHARAMPETH’,30000.00);
insert into borrow values(321,’MADHURI’,’ANDHERI’,20000.00);
insert into borrow values(375,’PRAMOD’,’VIRAR’,80000.00);
insert into borrow values(481,’KRANTI’,’NEHRU_PLACE’,30000.00);

select * from borrow;

180303105313 Page No:- 12


Faculty of Engineering & Technology
SubjectName : DBMS
Subject Code : 203105251
B.Tech CSE Year 2019-20 Semester 4th

Annexure No : 13

(iii) Perform following queries


(1) Retrieve all data from employee, jobs and deposit.
Soln:- select * from employee;
select * from job;
select * from deposit;

180303105313 Page No:- 13


Faculty of Engineering & Technology
SubjectName : DBMS
Subject Code : 203105251
B.Tech CSE Year 2019-20 Semester 4th

Annexure No : 14

(2)Give details of account no. and deposited rupees of customers having account opened
between dates 01-01-12 and 25-07-16.
Soln:-select a_no,amount from deposit where a_date between ‘1-JAN-12’ and ‘25-JUL-16’;

(3) Display all jobs with minimum salary is greater than 40000.
Soln:-select job_title from job where min_sal > 40000;

180303105313 Page No:- 14


Faculty of Engineering & Technology
SubjectName : DBMS
Subject Code : 203105251
B.Tech CSE Year 2019-20 Semester 4th

Annexure No : 15

(4) Display name and salary of employee whose department no is 120. Give alias name to
name of employee.
Soln:-select emp_name as ‘alias_name”,emp_sal from employee where dept_no=120;;

(5) Display employee no, name and department details of those employee whose
department
lies in(110,120).
Soln:-select emp_no,emp_name,dept_no from employee where dept_no between 110 and
120;
(iv) To study various options of LIKE Predicate
Description:-
Like:-
Syntax:-
select * from <table_name> where <column_name> like <like critation>;
The LIKE predicate compares a column of type CHAR or VARCHAR (string) with a
pattern. This pattern is also a string, but it may contain two characters with a special
meaning. The '_' (underscore) represents exactly one arbitrary character and '%'
(percent) represents a string of zero, one or more characters.

(1) Display all employee whose name start with ‘A’ and third character is ‘a’.
Soln:-select EMP_NAME from employee where EMP_NAME like ‘A_A%”;

(3) Display name, number and salary of those employees whose name is 4 characters
long and first two characters are ‘AM’.
Soln:-select EMP_NAME,EMP_SAL from employee where EMP_NAME like ‘AM__%’;

180303105313 Page No:- 15


Faculty of Engineering & Technology
SubjectName : DBMS
Subject Code : 203105251
B.Tech CSE Year 2019-20 Semester 4th

Annexure No : 16

(4) Display the non-null values of employees and also employee name second
character should be ‘n’ and string should be 5 character long.
Soln:-select * from employee where EMP_COMM is not null and EMP_NAME like ‘_N___’;

(5) Display the null values of employee and also employee name’s third character should be
‘r’.
Soln:-select * from employee where EMP_COMM is null and EMP_NAME like ‘__A%’;

Practical:-03
Aim:-To perform various data manipulation commands, aggregate
functions and sorting concept on all created tables.
(1) List total deposit from deposit.
Soln:-select sum(amount) “TOTAL DEPOSIT” from deposit;

(2) Give maximum loan from branch.


Soln:- select max(amount) “MAX AMOUNT” from deposit;

180303105313 Page No:- 16


Faculty of Engineering & Technology
SubjectName : DBMS
Subject Code : 203105251
B.Tech CSE Year 2019-20 Semester 4th

Annexure No : 17

(3) Count total number of customers.


Soln:- select count(distinct CNAME) “TOTAL NO OF CUSTOMER” from deposit;

(4) Create table supplier from employee with all the columns.
Soln:-create table supplier as select * from employee;
select * from employee;

(5) Delete all


the rows from supplier.
Soln:-truncate table supplier;

(6) Delete the detail of supplier whose sup_no is 104.


Soln:-alter table supplier where rename column EMP_NO to SUP_NO;
delete from supplier where sup_no=104;
select * from employee;

180303105313 Page No:- 17


Faculty of Engineering & Technology
SubjectName : DBMS
Subject Code : 203105251
B.Tech CSE Year 2019-20 Semester 4th

Annexure No : 18

(7) Destroy table sup1 with all the data.


Soln:-drop table supplier;

(8) Rename the table sup2.


Soln:- rename sup2 to supplier;
select * from supplier;

180303105313 Page No:- 18


Faculty of Engineering & Technology
SubjectName : DBMS
Subject Code : 203105251
B.Tech CSE Year 2019-20 Semester 4th

Annexure No : 19

(9) Update the value of employee name whose employee number is 105.
Soln:- update employee set EMP_NAME=’PRATIMA’ where EMP_NO=105;
select * from employee;

180303105313 Page No:- 19

You might also like