Professional Documents
Culture Documents
DBMS-Lab Manual
DBMS-Lab Manual
INDEX
SR. EXPT. PAGE NO. OF
TITLE
NO. NO. NO. PAGES
1 - Table of contents 01 01
1 - Revision Record Sheet 02 01
2 - Control copy holder 03 01
3 - General Instructions 04 01
4 - List of experiments - -
5 01 To study DDL-create and DML-insert commands. 05 07
1
Government Engineering College, Patan
Computer Science and Engineering Department
Database Management System (3130703)
2
Government Engineering College, Patan
Computer Science and Engineering Department
Database Management System (3130703)
3
Government Engineering College, Patan
Computer Science and Engineering Department
Database Management System (3130703)
GENERAL INSTRUCTIONS
4
Government Engineering College, Patan
Computer Science and Engineering Department
Database Management System (3130703)
PRACTICAL NO: 1
Theory:
Components of SQL:
(1) Data Definition Language (DDL): It is a set of SQL commands used to create,
modify and delete database structures and not the data. These commands are
auto commit. The examples are – CREATE, ALTER (modify), DROP (remove
table), TRUNCATE (remove all rows), COMMENT, RENAME.
(2) Data Manipulation Language (DML): It is a set of SQL commands that allows
changing data within database. These commands are not auto commit. The
examples are – INSERT, UPDATE, DELETE etc.
(3) Data Control Language (DCL): It is a set of SQL commands that control access
to data and to the database. The examples are –COMMIT, SAVEPOINT,
ROLLBACK, SET TRANSACTION, GRANT, REVOKE etc.
(4) Data Query Language (DQL): It is a component of SQL statement that allows
getting data from the database and imposing ordering upon it. The example is
SELECT.
(1) Char(size): Used to store character strings values of fixed length. The size in
determines the maximum number of characters that field can store. E.g. Name
char(20).
(3) Number(P, S): Used to store integer or float numbers. P denotes precession & S
denotes scale. E.g Salary number(6,2) will allow 6 digit long salary with 2 digit
after decimal.
Commands:
DDL commands:
5
Government Engineering College, Patan
Computer Science and Engineering Department
Database Management System (3130703)
1. Create Table Command: - it defines each column of the table uniquely. Each
column has minimum of three attributes, a name , data type and size.
Syntax:
CREATE TABLE <TABLE NAME> (<COL1> <DATATYPE>(<SIZE>),<COL2>
<DATATYPE><SIZE>));
Ex:
SQL> create table emp(empno number(4) , ename varchar2(10));
O/P: Table created.
Ex:
SQL> desc emp;
O/P:
Name Null? Type
----------------------------------------------------- -------- ------------------------------
EMPNO NUMBER(4)
ENAME VARCHAR2(10)
Syntax:
ALTER TABLE <TABLENAME> ADD(<NEW
COL><DATATYPE(SIZE),<NEW COL>DATATYPE(SIZE));
Ex:
SQL> alter table emp add(sal number(7,2));
O/P: Table altered.
O/P:
Name Null? Type
----------------------------------------------------- -------- ------------------------------
EMPNO NUMBER(4)
ENAME VARCHAR2(10)
SAL NUMBER(7,2)
6
Government Engineering College, Patan
Computer Science and Engineering Department
Database Management System (3130703)
Syntax:
ALTER TABLE <TABLENAME> DROP COLUMN <COL>;
Ex:
SQL> alter table emp drop column sal;
O/P: Table altered.
Syntax:
ALTER TABLE <TABLENAME> MODIFY (<COL>
<NEWDATATYPE>(<NEWSIZE>));
Ex:
SQL> alter table emp modify(ename varchar2(15));
O/P: Table altered.
Syntax:
RENAME <OLDTABLE> TO <NEW TABLE>;
Ex:
SQL> rename emp to emp1;
7
Government Engineering College, Patan
Computer Science and Engineering Department
Database Management System (3130703)
EMPNO NUMBER(4)
ENAME VARCHAR2(15)
Syntax:
TRUNCATE TABLE <TABLENAME>;
Ex:
SQL> truncate table emp1;
5. Destroying tables.
Syntax:
DROP TABLE <TABLENAME>;
Ex:
SQL> drop table emp;
DML-insert command:
6. Inserting Data into Tables: - once a table is created the most natural thing to do
is load this table with data to be manipulated later.
Syntax:
INSERT INTO <TABLENAME> (<COL1>,<COL2>) VALUES(<EXP>,<EXP>);
Ex:
SQL>insert into emp values(101, ‘Rakesh’);
O/P: 1 row created.
DQL Commands:
7. Viewing data in the tables: - Once data has been inserted into a table, the next
most logical operation would be to view what has been inserted.
Syntax:
SELECT * FROM TABLENAME;
8
Government Engineering College, Patan
Computer Science and Engineering Department
Database Management System (3130703)
8. Filtering table data: - While viewing data from a table, it is rare that all the data
from table will be required each time. Hence, SQL must give us a method of filtering
out data that is not required data.
Syntax:
SELECT <COL1>,<COL2> FROM <TABLENAME>;
Syntax:
SELECT * FROM <TABLENAME> WHERE <CONDITION>;
Syntax:
SELECT <COL1>,<COL2> FROM <TABLENAME> WHERE<CONDITION>;
PRACTICAL SET
DEPOSIT
ACTNO CNAME BNAME AMOUNT ADATE
100 ANIL VRCE 1000.00 1-MAR-95
101 SUNIL AJNI 5000.00 4-JAN-96
102 MEHUL KAROLBAGH 3500.00 17-NOV-95
104 MADHURI CHANDI 1200.00 17-DEC-95
105 PRMOD M.G.ROAD 3000.00 27-MAR-96
106 SANDIP ANDHERI 2000.00 31-MAR-96
107 SHIVANI VIRAR 1000.00 5-SEP-95
108 KRANTI NEHRU PLACE 5000.00 2-JUL-95
109 MINU POWAI 7000.00 10-AUG-95
BRANCH
BNAME CITY
VRCE NAGPUR
9
Government Engineering College, Patan
Computer Science and Engineering Department
Database Management System (3130703)
AJNI NAGPUR
KAROLBAGH DELHI
CHANDI DELHI
DHARAMPETH NAGPUR
M.G.ROAD BANGLORE
ANDHERI BOMBAY
VIRAR BOMBAY
NEHRU PLACE DELHI
POWAI BOMBAY
CUSTOMERS
CNAME CITY
ANIL CALCUTTA
SUNIL DELHI
MEHUL BARODA
MANDAR PATNA
MADHURI NAGPUR
PRAMOD NAGPUR
SANDIP SURAT
SHIVANI BOMBAY
KRANTI BOMBAY
NAREN BOMBAY
BORROW
LOANNO CNAME BNAME AMOUNT
201 ANIL VRCE 1000.00
206 MEHUL AJNI 5000.00
311 SUNIL DHARAMPETH 3000.00
321 MADHURI ANDHERI 2000.00
375 PRMOD VIRAR 8000.00
481 KRANTI NEHRU PLACE 3000.00
10
Government Engineering College, Patan
Computer Science and Engineering Department
Database Management System (3130703)
11. Give name of customers who opened account after date '1-12-96'.
12. Display customer names at branch ‘Virar’
13. Display all the branches in city Bombay.
14. List all the customers from city ‘Nagpur’.
15. Display the borrower detail in branch ‘Ajni’.
16. Display distinct cities from branch table.
17. Add contact_no. field in table customers with data type varchar2 and size 15.
18. Change the data type of contact_no field to number and size to 20.
19. Drop contact no. field in table customers
11
Government Engineering College, Patan
Computer Science and Engineering Department
Database Management System (3130703)
PRACTICAL NO: 2
Theory:
CONSTRAINTS
Constraints are part of the table definition that limits and restriction on the value
entered into its columns.
TYPES OF CONSTRAINTS:
1) Primary key
2) Foreign key/references
3) Check
4) Unique
5) Not null
6) Null
7) Default
1. Primary key: is used to uniquely identify a tuple in table. Can’t have null value.
a) At column level
Syntax:
CREATE TABLE <TABLE NAME>(<COL1><DATATYPE>(<SIZE>) PRIMARY
KEY, <COL2> <DATATYPE>(<SIZE>),……);
Ex:
SQL> create table std1(idno number(1) primary key, name varchar(10));
Table created.
SQL> /
Enter value for idno: 1
Enter value for name: xyz
12
Government Engineering College, Patan
Computer Science and Engineering Department
Database Management System (3130703)
b) At Table level
Syntax:
CREATE TABLE <TABLE NAME>(<COL1><DATATYPE>(<SIZE>), <COL2>
<DATATYPE>(<SIZE>), …, PRIMARY KEY(<COL1>,<COL2>));
Ex:
SQL> create table st1(idno number(1),name varchar(10), primary key(idno));
Table created.
SQL> /
Enter value for idno: 1
Enter value for name: def
old 1: insert into st1 values(&idno,'&name')
new 1: insert into st1 values(1,'def')
insert into st1 values(1,'def')
*
ERROR at line 1:
ORA-00001: unique constraint (DINESH.SYS_C008973) violated
SQL> create table p_s(idno number(1) primary key, name varchar(10) primary
key);
create table p_s(idno number(1) primary key, name varchar(10) primary key)
*
ERROR at line 1:
ORA-02260: table can have only one primary key
13
Government Engineering College, Patan
Computer Science and Engineering Department
Database Management System (3130703)
SQL> /
Enter value for idno: 1
Enter value for name: def
old 1: insert into p_s1 values(&idno,'&name')
new 1: insert into p_s1 values(1,'def')
1 row created.
SQL> /
Enter value for idno: 1
Enter value for name: abc
old 1: insert into p_s1 values(&idno,'&name')
new 1: insert into p_s1 values(1,'abc')
insert into p_s1 values(1,'abc')
*
ERROR at line 1:
ORA-00001: unique constraint (DINESH.SYS_C008976) violated
a) Column level
SQL> create table f_std1(idno number(1) references std1,cpi number(4,2));
Table created.
14
Government Engineering College, Patan
Computer Science and Engineering Department
Database Management System (3130703)
SQL> /
Enter value for idno: 3
Enter value for cpi: 3.4
old 1: insert into f_std1 values(&idno,&cpi)
new 1: insert into f_std1 values(3,3.4)
insert into f_std1 values(3,3.4)
*
ERROR at line 1:
ORA-02291: integrity constraint (DINESH.SYS_C008974) violated - parent key
not found.
b) Table level
SQL> create table f_st1(idno number(1),cpi number(4,2), foreign key(idno)
references st1(idno));
Table created.
3. Check
a) Column level
SQL> /
Enter value for idno: 2
Enter value for name: def
Enter value for cpi: 5.9
15
Government Engineering College, Patan
Computer Science and Engineering Department
Database Management System (3130703)
b) Table level
Table created.
4. Unique
a) Column Level
SQL> /
Enter value for idno: 1
Enter value for name: def
old 1: insert into std1 values(&idno,'&name')
new 1: insert into std1 values(1,'def')
insert into std1 values(1,'def')
*
ERROR at line 1:
16
Government Engineering College, Patan
Computer Science and Engineering Department
Database Management System (3130703)
IDNO NAME
---------- ----------
1 abc
def
b) Table Level
17
Government Engineering College, Patan
Computer Science and Engineering Department
Database Management System (3130703)
PRACTICAL SET
1. Demonstrate the use of PRIMARY KEY constraint at column level and write
your comments about the result.
2. Demonstrate the use of PRIMARY KEY constraint at table level and write
your comments about the result.
3. Demonstrate the use of FOREIGN KEY constraint at column level and write
your comments about the result.
4. Demonstrate the use of FOREIGN KEY constraint at table level and write
your comments about the result.
5. Demonstrate the use of FOREIGN KEY constraint with ON DELETE
CASCADE option and write your comments about the result.
6. Demonstrate the use of FOREIGN KEY constraint with ON DELETE SET
NULL option and write your comments about the result.
7. Demonstrate the use of UNIQUE constraint at column level and write your
comments about the result.
8. Demonstrate the use of UNIQUE constraint at table level and write your
comments about the result.
9. Demonstrate the use of NOT NULL constraint and write your comments about
the result.
10. Demonstrate the use of CHECK constraint and write your comments about
the result.
11. Demonstrate the use of DEFAULT constraint and write your comments about
the result.
12. Demonstrate the addition of primary key constraint in an already existing
table.
13. Demonstrate the deletion of primary key constraint.
14. Demonstrate assigning user defined names to a constraints.
15. Demonstrate the addition of constraint other than primary key in an already
existing table.
16. Demonstrate the deletion of constraint other than primary key.
Create the below given tables and insert the data accordingly.
18
Government Engineering College, Patan
Computer Science and Engineering Department
Database Management System (3130703)
job_title Varchar2(30)
min_sal Number(7,2)
max_sal Number(7,2)
19
Government Engineering College, Patan
Computer Science and Engineering Department
Database Management System (3130703)
a_date Date
20
Government Engineering College, Patan
Computer Science and Engineering Department
Database Management System (3130703)
21
Government Engineering College, Patan
Computer Science and Engineering Department
Database Management System (3130703)
PRACTICAL NO: 3
Syntax:
DELETE FROM <TABLENAME>;
Ex:
SQL> delete from emp;
Syntax:
DELETE FROM <TABLENAME> WHERE <CONDITION>;
Ex:
SQL> delete from emp where empno=103;
Syntax:
UPDATE <TABLENAME> SET <COL>=<EXP>,<COL>=<EXP>;
Ex:
SQL> update emp set ename='Suresh';
Syntax:
UPDATE <TABLENAME> SET <COL>=<EXP>, <COL>=<EXP>
WHERE <CONDITION>;
Ex:
SQL> update emp set ename='Suresh' where empno=101;
22
Government Engineering College, Patan
Computer Science and Engineering Department
Database Management System (3130703)
23
Government Engineering College, Patan
Computer Science and Engineering Department
Database Management System (3130703)
2 ram 56
3 syam 70
IDNO MARKS
---------- ----------
1 78
2 56
2 56
3 70
24
Government Engineering College, Patan
Computer Science and Engineering Department
Database Management System (3130703)
SQL> insert into std5 select * from std where name like 'r%';
3 rows created.
25
Government Engineering College, Patan
Computer Science and Engineering Department
Database Management System (3130703)
7. Logical operators: They are AND, OR, NOT. They can be used while
retrieving, updating records in WHERE clause.
(1) Select all employees either having salary more than 7000 or of department 5.
SQL>select * from emp where salary>7000 and dno=5;
eno ename salary dno pno
----- ---------- ---------- ---------- -------
e004 mehul 10000 5 2
8. Relational operators: They are =, >, <, >=, <=. They can be used while
retrieving, updating records in WHERE clause.
(2) Show all employees’ details who are having salary other than
2000,7000,12000.
SQL>select * from emp where salary not in (2000,7000,12000);
eno ename salary dno pno
----- ---------- ---------- ---------- ----------
e002 ram 5000 2 1
e004 mehul 10000 5 2
26
Government Engineering College, Patan
Computer Science and Engineering Department
Database Management System (3130703)
PRACTICAL SET
27
Government Engineering College, Patan
Computer Science and Engineering Department
Database Management System (3130703)
PRACTICAL NO: 4
Commands:
2. Dual table
D
-
X
2*3
----------
6
SQL> select 2/3 from dual;
2/3
28
Government Engineering College, Patan
Computer Science and Engineering Department
Database Management System (3130703)
----------
.666666667
SYSDATE
---------
01-FEB-07
ROUND(15.91)
------------
16
TO_NUMBER('12345')
------------------
12345
TO_CHAR(1
---------
$012,345
TO_CHA
------
$0123
29
Government Engineering College, Patan
Computer Science and Engineering Department
Database Management System (3130703)
I DOB
- ---------
1 30-JUL-06
ADD_MONTH
---------
03-DEC-06
SYSDATE LAST_DAY(
--------- ---------
03-AUG-06 31-AUG-06
MONTHS_BETWEEN('21-FEB-2006','23-JAN-2007')
-------------------------------------------
-11.06452
30
Government Engineering College, Patan
Computer Science and Engineering Department
Database Management System (3130703)
NEXT_DAY(
---------
05-AUG-06
I DOB
- ---------
1 30-JUL-06
2 22-JAN-05
3 03-APR-03
I TO_CHAR(
- --------
2 22-01-05
3 03-04-03
1 30-07-06
I TO_CHAR(DOB
- -----------
4 22ND-MAY-98
I TO_CHAR(DOB,
- ------------
4 TWENTY-TWO
I TO_CHAR(DOB,'D
- --------------
4 TWENTY-SECOND
31
Government Engineering College, Patan
Computer Science and Engineering Department
Database Management System (3130703)
UID
---------
510
3. Aggregation Functions:
COUNT(IDNO)
-----------
3
COUNT(IDNO)
-----------
1
COUNT(IDNO)
-----------
1
TOTALMARKS
----------
202
32
Government Engineering College, Patan
Computer Science and Engineering Department
Database Management System (3130703)
AVGMARKS
----------
67.3333333
AVGMARKS
----------
67.3333333
MAX(MARKS)
----------
89
MIN(MARKS)
----------
35
33
Government Engineering College, Patan
Computer Science and Engineering Department
Database Management System (3130703)
1 ramesh 78
2 ram 56
2 ram 56
3 syam 70
IDNO NAME
---------- ----------
1 ramesh
2 ram
3 syam
34
Government Engineering College, Patan
Computer Science and Engineering Department
Database Management System (3130703)
Practical Set
35
Government Engineering College, Patan
Computer Science and Engineering Department
Database Management System (3130703)
PRACTICAL NO: 5
Commands:
NAME||'HASSOCIALSECURITYNUMBER'||SSN||'ANDWOKINGINDEPT.NO'||DNO
--------------------------------------------------------------------------------
john has social security number 1 and woking in dept. no 5
frank has social security number 2 and woking in dept. no 5
alicia has social security number 3 and woking in dept. no 4
jenifer has social security number 4 and woking in dept. no 4
ramesh has social security number 5 and woking in dept. no 5
joyce has social security number 6 and woking in dept. no 5
ahmad has social security number 7 and woking in dept. no 4
james has social security number 8 and woking in dept. no 1
8 rows selected.
Practical Set
1. For each employee, display the employee number, job, salary, and salary
increased by 15% and expressed as a whole number. Label the column New
Salary
2. Modify your query no 4.(1) to display the subtraction of the old salary from the
new salary. Label it as Increase.
3. Write a query that displays the employee’s names with the first letter
capitalized and all other letters lowercase, and the length of the names, for all
employees whose name starts with J, A, or M. Give each column an
appropriate label. Sort the results by the employees’ last names.
4. Write a query that produces the following for each employee: <employee first
name> earns <salary> monthly. (Hint: use CONCAT() function).
5. Display the date on which the account was opened of customer in a format
that appears as Seventh of June 1994 12:00:00 AM. (Hint: use
TO_CHAR(date, 'fmDdspth "of" Month YYYY fmHH:MI:SS AM' )
6. Write a query to calculate the annual compensation of all employees
(sal+comm.).
36
Government Engineering College, Patan
Computer Science and Engineering Department
Database Management System (3130703)
PRACTICAL NO: 6
Commands:
INNER JOIN
Method 1:Theta-style
Method 2:Ansi-style
Query 2:
Method 1:Theta-style
DNAME NAME
-------- --------
admin jenifer
headqatr james
Method 2:Ansi-style
DNAME NAME
37
Government Engineering College, Patan
Computer Science and Engineering Department
Database Management System (3130703)
-------- --------
research frank
Query 3:
DNAME NAME
-------- --------
headqatr james
admin jenifer
DNAME NAME
-------- --------
admin jenifer
headqatr james
OUTER JOIN
Query: list of all employee names & also name of departments they manage.
SQL> select e.name,d.dname from empl e,deprt d where e.ssn=d.mgrssn(+);
NAME DNAME
-------- --------
john
frank research
alicia
jenifer admin
ramesh
joyce
ahmad
james headqatr
8 rows selected.
Query: list of all employee names & also name of departments they manage.
38
Government Engineering College, Patan
Computer Science and Engineering Department
Database Management System (3130703)
CROSS JOIN
Query: to retrieve for each employee a list of the names of their dependants.
employee supervis
-------- --------
john frank
frank james
alicia jenifer
jenifer james
ramesh frank
joyce frank
ahmad jenifer
39
Government Engineering College, Patan
Computer Science and Engineering Department
Database Management System (3130703)
7 rows selected.
Practical Set
40
Government Engineering College, Patan
Computer Science and Engineering Department
Database Management System (3130703)
PRACTICAL NO: 7
Commands:
8 rows selected.
41
Government Engineering College, Patan
Computer Science and Engineering Department
Database Management System (3130703)
ESSN PNO
--------- ---------
1 1
1 2
5 3
6 1
6 2
2 2
2 3
2 10
2 20
3 30
3 10
7 10
7 30
4 30
4 20
8 20
16 rows selected.
ESSN DEPNAME
--------- --------
2 alice
2 theod
42
Government Engineering College, Patan
Computer Science and Engineering Department
Database Management System (3130703)
2 joy
4 abner
1 michel
1 alice
1 eliza
7 rows selected.
SQL> select * from d_loc;
DNUMBER DLOC
--------- --------
1 hos
4 staffrd
5 bell
5 sugland
5 hos
SQL> select dno,count(ssn) " no of emps",avg(salary) "avg. salary" from empl group
by
dno;
DNO no of emps avg. salary
---------- ----------- -----------
1 1 55000
4 3 31000
5 4 33250
SQL> select dno,count(ssn) " no of emps",avg(salary) "avg. salary" from empl group
by
dno having avg(salary)>32000;
SQL> select dno,count(ssn) " no of emps",avg(salary) "avg. salary" from empl group
by
dno having count(ssn)=1;
43
Government Engineering College, Patan
Computer Science and Engineering Department
Database Management System (3130703)
SQL> select dno,count(ssn) " no of emps",avg(salary) "avg. salary" from empl group
by
rollup(dno,ssn);
44
Government Engineering College, Patan
Computer Science and Engineering Department
Database Management System (3130703)
Practical Set
45
Government Engineering College, Patan
Computer Science and Engineering Department
Database Management System (3130703)
PRACTICAL NO: 8
Commands:
SUBQUERIES
ID NAME
---------- --------
1 abc
2 pqr
3 xyz
4 def
5 ijk
ID ADDR CPI
---------- --------------- ----------
1 anand 8
2 baroda 7
3 ahmedabad 8.9
4 surat 5.9
5 rajkot 7.8
SQL> alter table stadd add constraint dev foreign key(id) references stdt;
Table altered.
SQL> select id,addr from stadd where id in(select id from stdt where name='def');
ID ADDR
---------- ---------------
4 surat
46
Government Engineering College, Patan
Computer Science and Engineering Department
Database Management System (3130703)
SQL> select id,addr from stadd where id not in(select id from stdt where name='def');
ID ADDR
---------- ---------------
1 anand
2 baroda
3 ahmedabad
5 rajkot
ID FNAME LNAME
--------- -------- --------
1 sunil shah
2 yash patel
FNAME LNAME
-------- --------
yash patel
47
Government Engineering College, Patan
Computer Science and Engineering Department
Database Management System (3130703)
SQL> select id,fname,lname from stu s where exists(select fname from teacher
where
tid=s.id);
ID FNAME LNAME
--------- -------- --------
1 sunil shah
2 yash patel
ID FNAME LNAME
--------- -------- --------
1 sunil shah
2 yash patel
ID FNAME LNAME
--------- -------- --------
1 sunil shah
2 yash patel
3 syam jain
4 akash gosai
SQL> select id,fname,lname from stu s where exists(select fname from teacher
where
tid=s.id);
ID FNAME LNAME
--------- -------- --------
1 sunil shah
2 yash patel
48
Government Engineering College, Patan
Computer Science and Engineering Department
Database Management System (3130703)
ID FNAME LNAME
--------- -------- --------
1 sunil shah
2 yash patel
ID FNAME LNAME
--------- -------- --------
1 sunil shah
2 yash patel
3 syam jain
4 akash gosai
ID FNAME LNAME
--------- -------- --------
1 sunil shah
2 yash patel
3 syam jain
SQL> select id,fname,lname from stu s where not exists(select fname,lname from
teacher
where tid=s.id);
ID FNAME LNAME
--------- -------- --------
4 akash gosai
49
Government Engineering College, Patan
Computer Science and Engineering Department
Database Management System (3130703)
ACC BR CURBAL
--- -- ---------
sa1 b1 25000
sa2 b2 350000
sa3 b1 3200
ca1 b1 450000
ca2 b1 112000
ca3 b2 2100
6 rows selected.
Query: list accounts along with the current balance, the branch to which it belongs &
avg. balance of that branch, to which the account belongs.
Query: list accounts along with the current balance & the branch no which it belongs,
having a balance more than the average balance of the branch, to which the account
belongs.
ACC CURBAL BR
--- --------- --
50
Government Engineering College, Patan
Computer Science and Engineering Department
Database Management System (3130703)
sa2 350000 b2
ca1 450000 b1
BR NAME
-- ---------------
b1 abc
b2 def
b3 pqr
b4 xyz
b5 lmn
b6 ijk
6 rows selected.
51
Government Engineering College, Patan
Computer Science and Engineering Department
Database Management System (3130703)
Query: List the employees of the bank in the order of the branch names at which
they are employed
SQL> select empno,(fname || '' ||lname) "name" ,dept from emp_mstr e order
by(select
name from branch_mstr b where e.branchno=b.branchno);
EM name DEPT
-- -------------------- ----------
e1 yashpatel marketing
e2 maheshpanchal loan
e3 rameshdave admin
e4 sureshparmar loan
Practical Set
1. Write a query to display the name and salary of any employee in the same
department as smith. Exclude smith.
2. Give name of customers who are depositors having same branch city of mr.
anil.
3. Give deposit details and loan details of customer in same city where pramod
is living.
4. Create a query to display the employee numbers and last names of all
employees who earn more than the average salary. Sort the results in
ascending order of salary.
5. Give names of depositors having same living city as mr. anil and having
deposit amount greater than 2000.
6. Display the department number, name, and job for every employee with job
same of snehal.
7. List the name of branch having highest number of depositors.
8. Give the name of cities where in which the maximum numbers of branches
are located.
9. Give name of customers living in same city where maximum depositors are
located.
52
Government Engineering College, Patan
Computer Science and Engineering Department
Database Management System (3130703)
PRACTICAL NO: 9
Practical List
53
Government Engineering College, Patan
Computer Science and Engineering Department
Database Management System (3130703)
PRACTICAL NO: 10
Commands:
[1] GRANT
User1: bhavini
SQL> desc s;
Name Null? Type
------------------------------- -------- ----
SNO NOT NULL CHAR(3)
SNAME VARCHAR2(8)
SNO SNAME
--- --------
s1 abc
s2 def
s3 pqr
s4 xyz
s5 ijk
s6 lmn
6 rows selected.
Grant succeeded.
User2: a1
SNO SNAME
----- -------
s1 abc
s2 def
s3 pqr
54
Government Engineering College, Patan
Computer Science and Engineering Department
Database Management System (3130703)
s4 xyz
s5 ijk
s6 lmn
6 rows selected.
User1: bhavini
User2: a1
SNO SNAME
--- --------
s1 abc
s2 def
s3 pqr
s4 xyz
s5 ijk
s6 lmn
s7 dgh
7 rows selected.
User1: bhavini
SNO SNAME
------- --------
s1 abc
s2 def
55
Government Engineering College, Patan
Computer Science and Engineering Department
Database Management System (3130703)
s3 pqr
s4 xyz
s5 ijk
s6 lmn
6 rows selected.
User2: a1
SQL> commit;
Commit complete.
User1: bhavini
SNO SNAME
--- --------
s1 abc
s2 def
s3 pqr
s4 xyz
s5 ijk
s6 lmn
s7 dgh
7 rows selected.
[2] REVOKE
User1: bhavini
Revoke succeeded.
User2: a1
56
Government Engineering College, Patan
Computer Science and Engineering Department
Database Management System (3130703)
PRACTICAL NO: 11
PROCEDURE
STEP 1: Start
STEP 2: Create the table with its essential attributes.
STEP 3: Insert the record into table
STEP 4: Update the existing records into the table
STEP 5: Delete the records in to the table
STEP 6: use save point if any changes occur in any portion of the record to undo its
original state.
STEP 7: use rollback for completely undo the records
STEP 6: use commit for permanently save the records.
COMMIT:
COMMAND DESCRIPTION: COMMIT command is used to save the
Records.
ROLLBACK:
COMMAND DESCRIPTION: ROLL BACK command is used to undo the
Records.
SAVE POINT:
COMMAND DESCRIPTION: SAVE POINT command is used to undo the
Records in a particular transaction.
57