DBMS Lab Manual
DBMS Lab Manual
LABORATORY MANUAL
Name
Roll No.
Section-Batch
Develop a platform for achieving globally acceptable level of intellectual acumen and
technological competence.
Create an inspiring ambience that raises the motivation level for conducting quality
research.
To inculcate creative thinking and problem solving skills through effective teaching,
learning and research.
To empower professionals with core competency in the field of Computer Science and
Engineering.
To foster independent and life long learning with ethical and social responsibilities.
PO5: Modern tool usage: Create, select, and apply appropriate techniques,
resources, and modern engineering and IT tools including prediction and modeling to
complex engineering activities with an understanding of the limitations.
PO6: The engineer and society: Apply reasoning informed by the contextual
knowledge to assess societal, health, safety, legal and cultural issues and the
consequent responsibilities relevant to the professional engineering practice.
comprehend and write effective reports and design documentation, make effective
presentations, and give and receive clear instructions.
PO11: Project management and finance: Demonstrate knowledge and
understanding of the engineering and management principles and apply these to
one‘s own work, as a member and leader in a team, to manage projects and in
multidisciplinary environments.
PO12: Life-long learning: Recognize the need for, and have the preparation and
ability to engage in independent and life-long learning in the broadest context of
technological change.
CO-PO MAPPING
Cos PO 1 PO PO PO PO PO PO PO PO PO PO PO PSO PSO
2 3 4 5 6 7 8 9 10 11 12 1 2
C308.1 3 3 3 1 3 0 0 2 2 1 2 3 2 2
C308.2 3 3 3 3 3 0 0 2 2 1 2 2 2 2
C308.3 3 2 2 3 3 0 0 2 2 1 2 2 2 2
C308.4 3 3 3 3 3 0 0 2 2 1 2 2 2 2
C308.5 3 3 3 3 3 0 0 2 2 1 2 3 2 2
C308 3.00 2.80 2.80 2.60 3.00 0.00 0.00 2.00 2.00 1.00 2.00 2.40 2.00 2.00
CO-PSO MAPPING
Cos PSO PSO
1 2
C308.1 2 2
C308.2 2 2
C308.3 2 2
C308.4 2 2
C308.5 2 2
C308 2.00 2.00
LIST OF EXPERIMENTS
INTRODUCTION
A Database Management System (DBMS) is a set of computer programs that controls the
creation, maintenance, and the use of a database. It allows organizations to place control of
database development in the hands of database administrators(DBAs) and other specialists. A
DBMS is a system software package that helps the use of integrated collection of data records
and files known as databases. It allows different user application programs to easily access
the same database. DBMSs may use any of a variety of database models, such as the network
model or relational model.
In large systems, a DBMS allows users and other software to store and retrieve data in
a structured way. Instead of having to write computer programs to extract information, user
can ask simple questions in a query language. Thus, many DBMS packages provide Fourth-
generation programming language(4GLs) and other application development features. It helps
to specify the logical organization for a database and access and use the information within a
database. It provides facilities for controlling data access, enforcing data integrity, managing
concurrency, and restoring the database from backups.
A DBMS also provides the ability to logically present database information to users. The
various functions of DBMS are Data Definition, Data manipulation, Data security and
integrity, Data recovery and concurrency and Data dictionary maintainance.
We can remove the unwanted data in the database, is NORMALIZATION, elimination of
redundant data. We have types in normalization like 0NF,1NF,2NF,3NF, Boyce-codd normal
form.
The benefits of normalization are:
1. Less storage space
2. Quicker updates
3. Less data inconsistency
4. Easier to add data
5. Clearer data relationships
Applications of DBMS
1. Data independence
2. Efficient data access
3. Data integrity
4. Data security
5. Concurrent access
6. Crash recovery.
1. Banking
2. Finance
3. Human resource
4. Tele communication
5. Airlines
6. Online ticket booking
7. E-seva
We can hide the data in the database i.e. the Data Abstraction. There are certain levels in
the data abstraction, they are Physical level, Logical level and View level. The overall design
of a database is called as SCHEMA. The data in the database is stored in the form of entities,
the tables. We can perform certain operations of DDL, DML commands for the entities in the
database like create, insert, delete, rename, alter, truncate, drop, update. A VIEW is a table
whose rows are not explicitly stored in the database but are computed as needed, it can be
used just like a base table. We can perform operations like create, update, delete, drop.
An entity-relationship model (ERM) is an abstract and conceptual representation
of data. Entity-relationship modelling is a database modelling method, used to produce a type
of conceptual schema or semantic data model of a system, often a relational database, and its
requirements in a top-down fashion. Diagrams created by this process are
called ER diagrams.
PREFACE
In order to develop the database systems, this lab enables the students to practice the efficient
and effective designing of database by using SQL Queries on Oracle. A DBMS also provides
the ability to logically present database information to users. The purpose of this laboratory
manual is to introduce undergraduate students to understand the benefits of database
designing for effective retrieval of information from the records. A DBMS is a system
software package that helps the use of integrated collection of data records and files known as
databases. It includes SQL Query writing, create views, Indexing, procedures and functions
and transaction control language. The manual contains procedures, and pre-experiment
questions to help students prepare for experiments.
This practical manual will be helpful for students of Computer Science & Engineering for
understanding the course from the point of view of applied aspects. Though all the efforts
have been made to make this manual error free, yet some errors might have crept in
inadvertently.
DO’s
DONT’S
1. Know the location of the fire extinguisher and the first aid box and how to use them in
case of an emergency.
4. Do not plug in external devices without scanning them for computer viruses.
10
While preparing the lab records, the student is required to adhere to the following guidelines:
Name
Roll No.
Section- Batch
INDEX
Experiment Experiment Date of Date of Faculty
No. Name Conduction Submission Signature
Students are provided with the details of the experiment (Aim, pre-experimental questions,
procedure etc.) to be conducted in next lab and are expected to come prepared for each lab
class.
Faculty ensures that students have completed the required pre-experiment questions and they
complete the in-lab programming assignment(s) before the end of class. Given that the lab
programs are meant to be formative in nature, students can ask faculty for help before and
during the lab class.
Students‘ performance will be assessed in each lab based on the following Lab Assessment
Components:
AC1: Written Work (Max. marks = 4)
AC2: Fundamental Knowledge to conduct Experiment (Max. marks = 4)
AC3: Experiment Completed Successfully (Max. marks = 4)
AC4: Questions Answered (Max. marks = 4)
AC5: Punctuality (Max. marks = 4)
In each lab class, students will be awarded marks out of 4 under each component head,
making it total out of 20 marks.
EXPERIMENT NO.-1
Aim: Write the queries for Data Definition and Data Manipulation Language.
Description:
Data Definition Language (DDL)
The DDL manages tables and index structure. The most basic items of the DDL are the
CREATE, RENAME, ALTER, DROP and TRUNCATE statements.
Data Manipulation Language (DML)
The DML is subset of SQL used to add, update and delete data.
Data Control Language (DCL)
The DCL authorizes users to access and manipulate data. Its main two statements are:
1. GRANT- authorizes one or more users to perform an operation or set of operations on
‗n‘objects.
2. REVOKE- it eliminates a grant, which may be the default grant.
Input
SQL> create table STUDENT(Roll_No number(10) primary key, Name varchar(30) not null,
Branch varchar(10) not null, Year number(2) not null, Section varchar(3), Hostel varchar(10),
F_name varchar(30) not null, Address varchar2(50) );
Output
Table created.
Input
SQL> create table BOOK(Book_id varchar2(10) primary key, Title varchar(10) not null,
Author varchar(30) not null, Publisher varchar(10) not null, Cost number(5,2), Copies
number(4) check(Copies>0),Unique(Title));
Output
Table created.
Input
SQL> create table TRANSACTION(Roll_No number(10) references STUDENT(Roll_No),
Book_id varchar2(10) references BOOK(Book_id ), Date_Issue date, Date_Return date, Fine
number(4,2),primary key(Roll_No, Book_id));
Output
Table created.
SQL Command:
SQL> create table empl018(empno varchar2(5), empname char(10), job char(10), city
char(10), salary number(10), deptno varchar(5));
Output:
Table created.
SQL Command:
SQL> create table projo18(pno varchar2(5), pname char(10), eno varchar2(5));
Output:
Table created.
SQL Command:
SQL> create table dept018(dno varchar(5), dname char(10), dlocation char(10), pno
varchar(10));
Output:
Table created.
EMPNO VARCHAR2(5)
EMPNAME CHAR(10)
JOB CHAR(10)
CITY CHAR(10)
SALARY NUMBER(10)
DEPTNO VARCHAR2(5)
SQL Command:
SQL> desc projo18;
Output:
Name Null? Type
PNO VARCHAR2(5)
PNAME CHAR(10)
ENO VARCHAR2(5)
SQL Command:
SQL> desc dept018;
Output:
Name Null? Type
DNO VARCHAR2(5)
DNAME CHAR(10)
DLOCATION CHAR(10)
PNO VARCHAR2(10)
Query: Insert the data into the tables using three different methods.
Syntax1: insert into tablename values(‗value1‘,‘value2‘,………);
Syntax2: insert into tablename(attr1, attr2,………)values(‗value1‘,‘value2‘,… ........... );
Syntax3: insert into tablename values(‗&attr1‘,‘&attr2‘,… ....... );
SQL Command:
SQL> insert into empl018 values('e1', 'Charu', 'HR', 'Agra', 50000, 'd1');
Output:
1 row created.
SQL Command:
SQL> insert into empl018(empno, empname, job, city, salary, deptno)values('e2',
'Meenamkshi', 'IT', 'Jhansi', 40000, 'd2');
Output:
1 row created.
SQL Command:
SQL> insert into empl018 values('&empno','&empname','&job','&city','&salary','&deptno');
Enter value for empno: e3
Enter value for empname: Ankita
Enter value for job: Marketting
Enter value for city: Delhi
Enter value for salary: 60000
Enter value for deptno: d3
old 1: insert into empl018 values('&empno','&empname','&job','&city','&salary','&deptno')
new 1: insert into empl018 values('e3','Ankita','Marketting','Delhi','60000','d3')
Output:
1 row created.
SQL Command:
SQL> /
Enter value for empno: e4
Enter value for empname: jai
Enter value for job: Finance
SQL Command:
SQL> /
Enter value for empno: e5
Enter value for empname: Anil
Enter value for job: Sales
Enter value for city: Bangalore
Enter value for salary: 10000
Enter value for deptno: d5
old 1: insert into empl018 values('&empno','&empname','&job','&city','&salary','&deptno')
new 1: insert into empl018 values('e5','Anil','Sales','Bangalore','10000','d5')
Output:
1 row created.
SQL Command:
SQL> /
Enter value for empno: e6
Enter value for empname: Shivani
Enter value for job: Sales
Enter value for city: Bangalore
Enter value for salary: 70000
Enter value for deptno: d6
old 1: insert into empl018 values('&empno','&empname','&job','&city','&salary','&deptno')
new 1: insert into empl018 values('e6','Shivani','Sales','Bangalore','70000','d6')
Output:
1 row created.
SQL Command:
SQL> insert into projo18 values('&pno','&pname','&eno');
Enter value for pno: p1
Enter value for pname: DBMS
Enter value for eno: e1
old 1: insert into projo18 values('&pno','&pname','&eno')
new 1: insert into projo18 values('p1','DBMS','e1')
Output:
1 row created.
SQL Command:
SQL> /
Enter value for pno: p1
Enter value for pname: DBMS
Enter value for eno: e5
old 1: insert into projo18 values('&pno','&pname','&eno')
new 1: insert into projo18 values('p1','DBMS','e5')
Output:
1 row created.
SQL Command:
SQL> /
Enter value for pno: p2
Enter value for pname: NW
Enter value for eno: e3
old 1: insert into projo18 values('&pno','&pname','&eno')
new 1: insert into projo18 values('p2','NW','e3')
Output:
1 row created.
SQL Command:
SQL> insert into dept018 values('&dno','&dname','&dlocation','&pno');
Enter value for dno: d1
SQL Command:
SQL> /
Enter value for dno: d1
Enter value for dname: cse
Enter value for dlocation: Delhi
Enter value for pno: p2
old 1: insert into dept018 values('&dno','&dname','&dlocation','&pno')
new 1: insert into dept018 values('d1','cse','Delhi','p2')
Output:
1 row created.
SQL Command:
SQL> /
Enter value for dno: d2
Enter value for dname: IT
Enter value for dlocation: delhi
Enter value for pno: p1
old 1: insert into dept018 values('&dno','&dname','&dlocation','&pno')
new 1: insert into dept018 values('d2','IT','delhi','p1')
Output:
1 row created.
SQL Command:
SQL> select * from empl018;
Output:
SQL Command:
SQL> select * from projo18;
Output:
PNO PNAME ENO
p1 DBMS e1
p1 DBMS e5
p2 NW e3
SQL Command:
SQL> select * from dept018;
Output:
DNO DNAME DLOCATION PNO
d1 cse Delhi p1
d1 cse Delhi p2
d2 IT delhi p1
e1 Charu
e2 Meenamkshi
e3 Ankita
e4 jai
e5 Anil
e6 Shivani
6 rows selected.
Add a column.
EMPNO VARCHAR2(5)
EMPNAME CHAR(10)
JOB CHAR(10)
CITY CHAR(10)
SALARY NUMBER(10)
DEPTNO VARCHAR2(5)
AGE NUMBER(3)
Drop column.
Query: Delete a column age from the table employee.
Syntax: alter table tablename drop column columnname
SQL Command:
SQL> alter table empl018 drop column age;
Output:
Table altered.
SQL> desc empl018;
Name Null? Type
EMPNO VARCHAR2(5)
EMPNAME CHAR(10)
JOB CHAR(10)
CITY CHAR(10)
SALARY NUMBER(10)
DEPTNO VARCHAR2(5)
EMPNO VARCHAR2(5)
EMPNAME VARCHAR2(15)
JOB CHAR(10)
CITY CHAR(10)
SALARY NUMBER(10)
DEPTNO VARCHAR2(5)
Rename a table.
Query: Rename a table empl018 to emp018.
Syntax: rename old tablename to new tablename;
SQL Command:
SQL> rename empl018 to emp018;
Output:
Table renamed.
Truncate a table.
Table created.
SQL> insert into faketble values('1','mini');
1 row created.
SQL> select * from faketble;
SN NAME
1 mini
Drop table.
Query: Delete the data as well as the structure of the table.
Syntax: drop table tablename;
SQL Command:
SQL> drop table faketble;
Output:
Table dropped.
SQL> desc faketble;
ERROR:
ORA-04043: object faketble does not exist
SQL> commit;
Commit complete.
SQL> spool off;
Post-Experiment Questions :
Q.1 Describe the benefits of Numeric functions.
Q.2 What are the aggreagate functions?
Q.3 Define a Table?
Q.4 What are constraints?
Q.5 Define a tuple and an attribute?
EXPERIMENT NO. 2
Aim : To explore ‘select’ statement using various clauses like where, order by, between,
like, group by, having and logical/relational operators.To implement various DML
statement.
Description :
Select and Create commands have been used along with various clauses like where, order by,
between , group by etc so as to simplify the query search.
Output
1 row created. (Rest other entries, try yourself)
Input
SQL> insert into TRANSACTION values (1209113096,‗BB-095‘, ‗23-08-2014‘ ,‘15-09-
2014‘,12.00);
Output
1 row created.
LOGICAL OPERATORS:
AND Command
Query: Display the employees whose salary is more than 30,000 and live in Agra.
Syntax: select attr1, attr2……… from tablename where condition;
SQL Command:
SQL> select empname from emp018 where salary>30000 and city='Agra';
Output:
EMPNAME
Charu
OR Operation
QUERY: Display the names of those employees who live in Agra or their salaries are more
than 70,000.
SYNTAX:
Select attrname from tablename where condition;
SQL COMMAND:
SQL> select empname from emp018 where salary>70000 or city='Agra';
OUTPUT:
EMPNAME
Charu
NOT Operation.
QUERY: Display the details of employees who do not live in Jhansi.
SYNTAX:
Charu
Ankita
jai
Anil
Shivani
Between Operation.
QUERY: Display the employee no., employee name and city of those employees whose
employee no., are between e1 and e2.
SYNTAX:
select attr1, attr2,…… from tablename where attrname between value1 and value2;
SQL COMMAND:
SQL> select empno, empname, city from emp018 where empno between 'e1' and 'e2';
OUTPUT:
EMPNO EMPNAME CITY
e1 Charu Agra
RELATIONAL OPERATORS:
< Operator
QUERY: Display those employees whose salaries are not more than 60,000.
SYNTAX:
Select attrname from tablename where condition;
SQL COMMAND:
SQL> select empname from emp018 where salary<60000;
OUTPUT:
EMPNAME
Charu
jai
Anil
> Operator
QUERY: Display the names of those employees whose salaries are more than 70,000.
SYNTAX:
Select attrname from tablename where condition;
SQL COMMAND:
SQL> select empname from emp018 where salary>70000;
OUTPUT:
no rows selected
= Operator.
QUERY: Display the names of those employees who are working for department d4.
SYNTAX:
Select attrname from tablename where condition;
SQL COMMAND:
SQL> select empname from emp018 where deptno='d4';
OUTPUT:
EMPNAME
jai
Display selected rows and selected columns.
QUERY: Display the employee no., employee name and salary from table employee where
salary=50,000.
SYNTAX:
Select attr1, attr2,……… from tablename where condition;
SQL COMMAND:
SQL> select empno,empname,salary from emp018 where salary=50000;
OUTPUT:
EMPNO EMPNAME SALARY
e1 Charu 50000
e4 jai 50000
Like Command
Query1: Display empno, empname of those employees whose name start from ‗r‘.
Syntax: select attribute from tablename where condition;
Command:
SQL> select empno,empname from emp018 where empname like 'C%';
Output:
EMPNO EMPNAME
e1 Charu
Query2: Display empno,empname of those employee whose name contain substring ‗up‘.
Syntax: select attribute from tablename where condition;
Command:
SQL>selectempno,empname from emp018 where empname like '%hi%';
Output:
EMPNO EMPNAME
e6 Shivani
Query3: Display empno,empname of those employee whose name 2rd alphabet is ‗u‘.
Syntax:select attribute from tablename where condition;
Command:
SQL>selectempno,empname from emp018 where empname like '_i%';
Output:
EMPNO EMPNAME
e4 jai
e5 Anil
e6 Shivani
In Command
Query4: Display empno, city & name of those employees who are either ‗HR‘ or ‗Director‘.
Syntax: select attribute from tablename where condition;
Command:
SQL>selectempno,empname from emp018 where job='hr' or job='director';
Output:
EMPNO EMPNAME CITY
e1 Charu Agra
NOT IN command
Query5: Display empno, city & empname of those who do not live in agra.
Syntax: select attribute from tablename where condition;
Command:
SQL> select empno,city,empname from emp018 where city not in 'agra';
Output:
EMPNO EMPNAME CITY
e3 Ankita Delhi
e4 jai Bangalore
e5 Anil Bangalore
e6 Shivani Bangalore
Order by command
Query7: Display the records of table employee in descending order of their salary
Syntax: select * from tablename order by attribute desc;
Command:
SQL> select * from emp018 order by salary desc;
Output:
EMPNO EMPNAME JOB CITY SALARY DEPTN
-
e6 Shivani Sales Bangalore 70000 d6
e3 Ankita Marketting Delhi 60000 d3
e1 Charu HR Agra 50000 d1
e4 jai Finance Bangalore 50000 d4
e5 Anil Sales Bangalore 10000 d5
6 rows selected.
Lower function
Query1: Display the name of all employees in lower case
Syntax: select lower( attribute) from tablename;
Command:
SQL> select lower(empname) from emp018;
Output:
LOWER(EMPNAME)
charu
ankita
jai
anil
shivani
6 rows selected.
Upper function
Query: Display the name of all employees in upper case
Syntax: select upper( attribute) from tablename;
Command:
SQL> select upper(empname) from emp018;
Output:
UPPER(EMPNAME)
CHARU
ANKITA
JAI
ANIL
SHIVANI
6 rows selected.
Initcap function
Query: Make first character of all name as capital
Syntax: select initcap( attribute) from tablename;
Command:
SQL> select initcap(empname) from emp018;
Output:
INITCAP(EMPNAME
Charu
Ankita
Jai
Anil
Shivani
6 rows selected.
Substring function
Query4: Display first four characters of the designation that the employees hold
Syntax: select substr( attribute) from tablename;
Command:
SQL>selectsubstr(job,1,4) from emp018;
Output:
SUBS
HR
Mark
Fina
Sale
Sale
6 rows selected.
ASCII function
Query: Print the ascii value of first character of column city.
Syntax: select ascii( attribute) from tablename;
Command:
SQL> select ascii(city) from emp018;
Output:
ASCII(CITY)
65
68
66
66
66
6 rows selected.
Instring function
Query5: Print the name of second occurrence of letter ‗i‘ in name of employees
Syntax: select instr( attribute) from tablename;
Command:
SQL> select instr(empname,'i',1,2) from emp018;
Output:
INSTR(EMPNAME,'I',1,2)
0
0
0
0
7
6 rows selected.
Ltrim command
Query: Remove all the white spaces from the left of the string.
Syntax: select ltrim(‗ string‘)from dual;
Command:
SQL> select ltrim(' Meenakshi')from dual;
Output:
LTRIM('ME
Meenakshi
Rtrim command
Query: Remove all the white spaces from the right of the string.
Syntax: select rtrim(‗ string ‘)from dual;
Command:
SQL> select rtrim('Meenakshi ')from dual;
Output:
RTRIM('ME
Meenakshi
Concatenate command
Query: join the attribute of empname & city of all employees
Syntax: select concat( attribute) from tablename;
Command:
SQL> select concat(empname,city) from emp018;
Output:
CONCAT(EMPNAME,CITY)
Charu Agra
Ankita Delhi
jai Bangalore
Anil Bangalore
Shivani Bangalore
6 rows selected
Replace command
Query9: replace the attribute empname which contain the string ‗ ‗
Syntax: select replace(attribute,‘a‘,‘b‘) from tablename;
Command:
SQL> select replace(empname, 'an','am')from emp018;
Output:
REPLACE(EMPNAME,'AN','AM')
Charu
Ankita
jai
Anil
Shivami
6 rows selected.
NUMERIC FUNCTIONS:
Absolute function
Query: display the value of -8.5 in dual
Syntax: select abs(-number) from dual;
Command:
SQL>select abs(-8.5) from dual;
Output:
ABS(-8.5)
8.5
Title: Round function
Quer11: display the rounded value of 23.45 to two decimal places
Syntax: select round( number) from dual;
Command:
SQL> select round(23.45) from dual;
Output:
ROUND(23.45)
23
Power command
Query12: display the value of pow (2,3) in dual
Syntax: select power(a,b) from dual;
Command:
SQL> select power(2,3) from dual;
Output:
POWER(2,3)
8
Square root function
Query13:display square root of 65536 from dual
Syntax: select sqrt(number) from dual;
Command:
SQL> select sqrt(65536)from dual;
Output:
SQRT(65536)
256
Power exponent
Query14: display the value of exponent raised to 3.3 from dual
Syntax: select exp(number) from dual;
Command:
SQL> select exp(3.3)from dual;
Output:
EXP(3.3)
27.1126389
Greatest function
Query15: display largest number from dual
Syntax: select greatest (x,y,z) from dual;
Command:
SQL> select greatest(2,3,100,200,300,400)from dual;
Output:
GREATEST(2,3,100,200,300,400)
400
Least function
Query16: display the least number among the dual
Syntax: select least (x,y,z) from dual;
Command:
SQL> select least(-1,2,0,4,5)from dual;
Output:
LEAST(-1,2,0,4,5)
-1
Mod command
Query17: display the remainder of 15/7
Syntax: select mod(a,b) from dual;
Command:
SQL> select mod(15,7)from dual;
Output:
MOD(15,7)
Truncate command
Query18: display the value of 1284.6189 truncate to one decimal place
Syntax: select trunc(decimal_number,x) from dual;
Command:
SQL> select trunc(23.4567,1)from dual;
Output:
TRUNC(23.4567,1)
23.4
Sin function.
Query21: display the sine value of 60.
Syntax: select sin(number)from dual;
Command:
SQL> select sin(60)from dual;
Output:
SIN(60)
-.30481062
cos function.
Query22: display the cos value of 32.
Syntax: select cos(number)from dual;
Command:
SQL> select cos(32)from dual;
Output:
COS(32)
.834223361
Output:
TAN(92)
1.24427006
Date function
Query24: add four months to the system data and display it
Syntax: select add months(sysdate,a) from dual;
Command:
SQL> select add_months(sysdate,4)from dual;
Output:
ADD_MONTH
01-JUN-12
Month between
Query25: display the number of months that exist between two dates
Syntax: select months_between(date1,date2) from dual;
Command:
SQL> select months_between('1 feb 12','26 sep 11')from dual;
Output:
MONTHS_BETWEEN('1FEB12','26SEP11')
4.19354839
Next date
Query26: display the next date of month using system date
Syntax: select next_date(date,‘day‘) from dual;
Command:
SQL> select next_day('1 feb 12', 'wednesday')from dual;
Output:
NEXT_DAY(
08-FEB-12
29-FEB-12
Sysdate function
Query28: display the system date when the database is stored
01-FEB-12
Conversion Function
Query29: to convert the character type value of 500 to number type and display it to_number
(‗500‘)
Syntax: select to_number(‗x‘) from dual;
Command:
SQL> select to_number('500')from dual;
Output:
TO_NUMBER('500')
500
Query30: convert the number data type of 17145 to character data type and display in the
format $017,145
Syntax: selectto_char(number,‘$099,999‘) from dual;
Command:
SQL> select to_char(17145,'$099,999')from dual;
Output:
TO_CHAR(1
$017,145
Date Conversion
Query31: convert date datatype of system date to mm_dd_yyyy
Syntax: select to_ char(sysdate,‘mm-dd-yyyy‘) from dual;
Command:
SQL> select to_char(sysdate,'month-dd-yyyy')from dual;
Output:
TO_CHAR(SYSDATE,'
february -01-2012
Aggregate Functions:
Average function
Query32: Calculate the average salary of the employees from the table employee and name
the calculated average as salary1.
Syntax: select avg(salary) newname from tablename;
Command:
SQL> select avg(salary) salary1 from emp018;
Output:
SALARY1
48000
MAX Function
Query33: Calculate the maximum salary of the employees from the table employee and name
the calculated maximum salary as maxsalary.
Syntax: select max(salary) newname from tablename;
Command:
SQL> select max(salary) maxsalary from emp018;
Output:
MAXSALARY
70000
MIN Function
Query34: Calculate the minimum salary of the employees from the table employee and name
the calculated maximum salary as minsalary.
Syntax: select min(salary) newname from tablename;
Command:
SQL> select min(salary) minsalary from emp018;
Output:
MINSALARY
10000
Count Function
Query35: Calculate the total number of records in the table employee.
Syntax: select count(attr)from tablename;
Command:
SQL> select count(empno) from emp018;
Output:
COUNT(EMPNO)
SUM Function
Query36: Calculate the total salary of all the employees in the table employee.
Syntax: select sum(salary)from tablename;
Command:
SQL> select sum(salary) from emp018;
Output:
SUM(SALARY)
240000
Post-Experiment Question:
Q.1 How primary key can be used to retrieve the data base?
Q.2 How annual salaries can be computed of the employees?
Q.3 Is it possible to change the date of the system?
Q.4 What are constraints?
EXPERIMENT NO. 3
Aim : To implement nested and correlated queries and to create various views and
indexes and to implement Cursors and triggers using PL/SQL.
Description : Queries can be nested and correlated using JOINS. Different types of joins can
be used to correlate different queries.A view is like a virtual table: It is defined by a view
definition query which describes how to compute the view contents. DBMS stores the view
definition instead of the view contents. It can be used in queries just like a regular table.An
index on attribute Creates auxiliary persistent data structure..
Tables:
emp018:
EMPNO EMPNAME JOB CITY SALARY DEPTN MGRNO
projo18:
PNO PNAME ENAME
p1 DBMS Charu
p1 DBMS Charu
p2 NW Ankita
p1 DBMS jai
p1 DBMS anil
p1 DBMS Shivani
p4 CO shivani
p6 Automata Charu
p8 SQL jai
asto018:
PNO ENO
p2 e3
p4 e6
p6 e1
p8 e4
p1 e3
p1 e1
p1 e4
p1 e5
p1 e6
e1 Charu
e3 Ankita
e4 jai
e5 Anil
e6 Shivani
e3 Ankita
Query 3: Get the employee number of the employees who are not working on ‗p1‘.
Syntax: (select attrs.. from table1,table2 where condition)minus(select attr from table1,table2
where condition1 and condition2);
SQL Command:
SQL> (select empno,empname from emp018,asto018 where emp018.empno=asto018.eno)
minus (select empno,empname from emp018,asto018 where emp018.empno=asto018.eno and
pno='p1');
Output:
no rows selected
DBMS Charu e3
DBMS Charu e1
DBMS Charu e5
DBMS Charu e6
DBMS Charu e4
DBMS Charu e3
DBMS Charu e1
DBMS Charu e5
DBMS Charu e6
DBMS Charu e4
DBMS jai e3
DBMS jai e1
DBMS jai e5
DBMS jai e6
DBMS jai e4
DBMS Shivani e3
DBMS Shivani e1
DBMS Shivani e5
DBMS Shivani e6
DBMS Shivani e4
DBMS anil e3
DBMS anil e1
DBMS anil e5
DBMS anil e6
DBMS anil e4
NW Ankita e3
CO shivani e6
Automata Charu e1
SQL jai e4
29 rows selected.
DBMS Charu e3
DBMS Charu e1
DBMS Charu e5
DBMS Charu e6
DBMS Charu e4
DBMS Charu e3
DBMS Charu e1
DBMS Charu e5
DBMS Charu e6
DBMS Charu e4
DBMS jai e3
DBMS jai e1
DBMS jai e5
DBMS jai e6
DBMS jai e4
DBMS Shivani e3
DBMS Shivani e1
DBMS Shivani e5
DBMS Shivani e6
DBMS Shivani e4
DBMS anil e3
DBMS anil e1
DBMS anil e5
DBMS anil e6
DBMS anil e4
NW Ankita e3
CO shivani e6
Automata Charu e1
SQL jai e4
29 rows selected.
SQL Command:
SQL> select empno,empname from emp018 where empno in(select eno from asto018 where
pno='p1');
Output:
EMPNO EMPNAME
e1 Charu
e3 Ankita
e4 jai
e5 Anil
e6 Shivani
Query 7: Get the details of the employees working on ‗p1‘ or ‗p2‘.
Syntax: select attr1,attr2…from table1 where exists(select * from table2 where(condition1 or
condition2)and linkingcondition;
SQL Command:
SQL> select empno,empname from emp018 where exists(select * from asto018 where
(pno='p1' or pno='p2')and asto018.eno=emp018.empno);
Output:
EMPNO EMPNAME
e1 Charu
e3 Ankita
e4 jai
e5 Anil
e6 Shivani
Query 8: Get the employee no. of the employees who do not work on ‗p1‘.
Syntax: select distinct attr from table1 where attr not in(select attr from table2 where
condition);
SQL Command: select distinct empno from emp018 where eno not in(select eno from
asto018 where pno=‘p1‘);
Output:
no rows selected
Query 9: Get the details of the employees who work on all the projects.
Syntax: select attr from table1 where not exists(select * from table2 where not exists(select *
from table3 linkcond1 and linkcond1));
SQL Command:
SQL> select empno from emp018 where not exists(select * from projo18 where not
exists(select * from asto018 where asto018.eno=emp018.empno and
asto018.pno=projo18.pno));
Output:
no rows selected
Query 10: Retrieve the names of the employees who have the same names as their managers.
Syntax: select attr1 from table1 where linkattr in(select attr2 from table1 alias);
SQL Command:
SQL> select emp018.empname from emp018 where empno in(select mgr.mgrno from
emp018 mgr);
Output:
EMPNAME
Query 1: List the employees in the order of the project numbers they are assigned to.
Syntax: select attr1,attr2 from table order by attr asc;
SQL Command:
SQL> select pno,ename from projo18 order by pno;
Output:
PNO ENAME
p1 Charu
p1 Charu
p1 jai
p1 anil
p1 Shivani
p2 Ankita
p4 shivani
p6 Charu
p8 jai
Query2: Find out all the employees having the same name as their managers.
Syntax: select attr from table alias where linkattr in(select attr from table alias)
SQL Command:
SQL> select emp018.empname from emp018 where mgrno in(select mgr.empno from
emp018 mgr);
Output:
EMPNAME
Charu
Ankita
Anil
Shivani
Views:
Query1:- Create a view to display details of employee not working on any project.
Syntax:-
Create view ―viewname‖ as ―query‖.
Command:-
SQL> create view emppro as select * from emp018 where empno NOT IN(select empno from
asto018);
Output:-
View created.
Query2:- Create a view to display employee name and project name not working on any
project.
Syntax:-
Create view ―viewname‖ as ―query‖.
Command:-
SQL> create view myproj as select empname,projno from emp018,asto018 where
emp018.empno=asto018.eno AND pno IN('p11','p23');
Output:-
View created.
Union
Command:-
SQL> select eno from asto018 where pno='p11' UNION select eno from asto018 where
pno='p21';
Output:-
EMPNO
e1
e2
e6
Intersection
Query2:-Find the employees who are working on project p21 and p32.
Syntax:-
Select ―columnname‖ from ―tablename‖ where ―condition‖INTERSECT select
―columnname‖ from ―tablename‖ where ―condition‖.
Command:-
SQL> select eno from asto018 where pno='p21' Intersect select eno from asto018 where
pno='p32';
Output:-
EMPNO
e2
e6
Minus
Query3:-Find the employees who are working on project p11 and not in p21.
Syntax:-
Select ―columnname‖ from ―tablename‖ where ―condition‖MINUS select ―columnname‖
from ―tablename‖ where ―condition‖.
Command:-
SQL> select eno from asto018 where pno='p11' MINUS select eno from asto018 where
pno='p21';
Output:-
EMPNO
e1
Implementation of Restrictions
Query1:-Create a table Employee with all fields as mandatory (not null) and make empno as
the primary key.
Syntax:-
Create table ―tablename‖(―column1‖ type primary key,‖column2‖ not null).
Command:-
SQL> create table em018 (empno varchar2(20) PRIMARY KEY,empname varchar2(20) not
null,salary number(6) not null);
Output:-
Table created.
Query2:-Create a table Employee such that empno. are unique across the entire column and
rest all fields are not null.
Syntax:-
Create table ―tablename‖(―column1‖ type unique key,‖column2‖ not null).
Command:-
SQL> create table emp18 (empno varchar2(20) UNIQUE,empname varchar2(20) not
null,salary number(6) not null);
Output:-
Table created.
Query3: Add a constraint to the salary attribute in employee such that minimum salary is
1000.
Syntax:-
Create table ―tablename‖(―column1‖ type primary key,‖column2‖ not null,check(sal>=1000).
Command:-
SQL> create table emp18 (empno varchar2(20) UNIQUE,empname varchar2(20) not
null,salary number(6) check(salary>=1000));
Output:-
Table created.
Syntax:-
Alter table ―Tablename‖ drop constraint uk .
Command:-
SQL> alter table emp18 drop constraint uk;
Output:-
Table altered.
Output:-
Table altered.
Post-Experiment Questions:
EXPERIMENT NO. 4
Description:
Integrity Constraints are used to apply business rules for the database tables.The
constraints available in SQL are Foreign Key,Not Null, Unique, Check. Constraints can
be defined in two ways:
1) The constraints can be specified immediately after the column definition. This is
called column-level definition.
2) The constraints can be specified after all the columns are defined. This is called table-
level definetion.
Write PL/SQL program to display the name of the student of 4th year in CSE branch,
whose Roll_No is 1005.
Input
SQL>SET SERVEROUTPUT ON;
SQL>declare rollno STUDENT.Roll_No%type;
br STUDENT.Branch%type;
yr STUDENT.Branch%type;
nm STUDENT.Name%type;
Begin
rollno:=&rollno;
select Branch INTO br, YEAR INTO yr , Name INTO nm
From STUDENT where Roll_No=rollno;
IF yr=4
then
IF br=‘CSE‘
then
DBMS_OUTPUT.PUT_LINE(‗NAME OF STUDENT OF CSE BRANCH OF 4 YEAR
IS:‘||nm);
END IF;
ELSE
DBMS_OUTPUT.PUT_LINE(‗WRONG VALUE… .....STUDENT IS NOT OF SPECIFIED
BRANCH OR YEAR‘);
END IF;
END;Output
Enter value for rollno: 1005
old 6: rollno:=&rollno;
new 6 : rollno:=1005;
PL\SQL procedure successfully completed.
NAME OF STUDENT OF CSE BRANCH OF 4 YEAR IS: SONIA
Write appropriate program in PL/SQL for restricting user to enter the data in BOOK
table on Sunday and also beyond the working hours (say after 5 PM).
Input
―It is not clear in the question or the database about the time or day‖
Input
SQL>SET SERVEROUTPUT ON;
SQL>declare bookid BOOK.Book_id%type;
tit BOOK.Title%type;
ath BOOK . Author%type;
pub BOOK.Publisher%type;
ct BOOK.Cost%type;
cp BOOK.Copies%type;
X INT;
Begin
X:=1;
WHILE(X<=5)
LOOP
select Book_id INTO bookid, Title INTO tit, Author INTO ath, Publisher INTO pub, Cost
INTO ct, Copies INTO cp
from(select * from BOOK order by Cost ) where ROWNUM=X;
DBMS_OUTPUT.PUT_LINE(bookid||‘ ‗||tit||‘ ‗||ath||‘ ‗||pub||‘ ‗||ct||‘ ‗||cp);
X:=X+1;
END LOOP:
END;
Output
PL\SQL procedure successfully completed.
Write a PL/SQL block in order to calculate the factorial of a number.
PL/SQL Block:
end; /
Output:
Write a PL/SQL block to update the salary of a given employee whose salary is less than
20000 to 25000 from the employee table.
PL/SQL block:
Output:
Post-Experiment Questions:
Q.1 What is a loop?
Q.2 Which command displays the output in PL/SQL Program?
Q.3 Why do we use loops in our program?
EXPERIMENT NO. 5
Description:
A cursor is a pointer to this context area. PL/SQL controls the context area through a cursor.
A cursor holds the rows (one or more) returned by a SQL statement. The set of rows the
cursor holds is referred to as the active set. Triggers are stored programs, which are
automatically executed or fired when some events occur. Triggers are, in fact, written to be
executed in response to any of the following events −
A database manipulation (DML) statement (DELETE, INSERT, or UPDATE)
A database definition (DDL) statement (CREATE, ALTER, or DROP).
A database operation (SERVERERROR, LOGON, LOGOFF, STARTUP, or
SHUTDOWN).
Triggers can be defined on the table, view, schema, or database with which the event is
associated.
Query: Write a PL/SQL code to display the details of all the employees except director
having salary more than Rs.2500. For the managers having salary more than 2500, the salary
increment is fixed as Rs. 500 and for the analysts having salary more than Rs. 2500, the
salary incremented is Rs. 750. Update the salaries of these employees.
OUTPUT:
records fetched are
Triggers:
Query: Write a transparent audit system from a table cust_master. The system must keep
track of records that are being deleted or updated.
TABLE:
c1 Meenakshi 26-SEP-91
c2 Shivani 27-DEC-92
c3 Shantanu 30-SEP-72
Trigger created.
c3 Shantanu 30-SEP-72
SQL>update cust_mast set dob=‘25-nov-1990‘ where cust_no=‘c2‘;
1 row updated.
SQL>select * from audit_sys;
CUST CUST_NAME DOB
c3 Shantanu 30-SEP-72
c2 Shivani 27-DEC-92
Post-Experiment Questions :
EXPERIMENT NO. 6
Description:
A Procedure is a subprogram is a program unit/module that performs a particular task. These
subprograms are combined to form larger programs. This is basically called the 'Modular
design'. A subprogram can be invoked by another subprogram or program which is called
the calling program.
A subprogram can be created −
At the schema level
Inside a package
Inside a PL/SQL block
101 Nithya
102 Maya
101 Nithya
102 Maya
103 SCOTT
RESULT:
begin
salary:=&sa;
if salary>5000 then
bonus:=salary*0.5;
else
bonus:=0;
end if;
dbms_output.put_line(bonus);
end;
Enter value for sa: 10000
old 5: salary:=&sa; new
5: salary:=10000; 5000
PL/SQL procedure successfully completed.
SQL>
Enter value for num: 407
old 6: i:=#
new 6: i:=407;
407IS AN ARMSTRONG NUMBER
PL/SQL procedure successfully completed.
dbms_output.put_line(i||'*'||n||'='||s);
end loop;
end;
Enter value for ulimit: 1
old 8: a:=&ulimit; new
8: a:=1;
Enter value for llimit: 10
old 9: b:=&llimit;
new 9: b:=10; Enter
value for n: 5
old 10: n:=&n;
new 10: n:=5;
1*5=5 2*5=10
3*5=15 4*5=20
5*5=25 6*5=30
7*5=35 8*5=40
9*5=45
10*5=50
Post-Experiment Questions :
EXPERIMENT NO. 7
Description:
Payroll is the process by which employers pay an employee for the work they have
completed. A payroll system is software designed to organize all the tasks of employee
payment and the filing of employee taxes. These tasks can include keeping track of hours,
calculating wages, withholding taxes and deductions, printing and delivering checks and
paying employment taxes to the government.
Payroll software often requires very little input from the employer. The employer is
required to input employee wage information and hours—then the software calculates the
information and performs withholdings automatically. Most payroll software is automatically
updated whenever a tax law changes and will remind employers when to file various tax
forms.
Steps:
1. Create a database for payroll processing which request the using SQL
4. Click add button and select oracle in ORA home 90, click finish
5. A window will appear given the data source home as oracle and select TNS source name as
lion and give the used id as SWTT
7. The above procedure must be follow except the table , A select the table as salary
8. Write appropriate Program in form each from created in VB from each from created in VB
form project.
Table created.
Table created.
Trigger created.
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
End Sub
Private Sub delte_Click()
Adodc1.Recordset.Delete MsgBox "Record Deleted"
If Adodc1.Recordset.EOF = True
Then Adodc1.Recordset.MovePrevious
End If
End Sub
Private Sub exit_Click()
Unload Me
End Sub
Private Sub main_Click()
Form1.Show
End Sub Private
Sub
modify_Click()
Adodc1.Recordset.Update
End Sub
Output:
RESULT:
EXPERIMENT NO. 8
Description:
The Library Information Systems unit (LIS) is responsible for computer equipment,
communications infrastructure, and library information resources.
The unit is in charge of library computer systems, acquisition, software installation and
upgrading, management, backup, and restoration, as well as providing technical support and
the repair of library computers (within library staff offices and public workstations within the
library). In addition, the unit staff is involved in the development of information systems,
their implementation and maintenance, including website creation and digital project support.
Steps:
1. Create a database for library which request the using SQL
4. Click add button and select oracle in ORA home 90, click finish
5. A window will appear given the data source home as oracle and select TNS source
name as lion and give the used id as SWTT
7. The above procedure must be follow except the table , A select the table as library
8. Write appropriate Program in form each from created in VB from each from created in
VB form project.
WHERE B.title LIKE '%<user input>%' AND B.author LIKE '%<user input>%' AND
B.year <= <user input> AND B.year >= <user input>;
/* Find all copies of a book (used for placing holds or viewing detailed
information). */
SELECT BM.media_id, S.description,
nvl((SELECT SI.name
FROM Stored_In SI
WHERE SI.media_id = BM.media_id), 'none') AS name
FROM BookMedia BM, Media M, Status S
WHERE BM.ISBN = <user input> AND M.media_id = BM.media_id AND S.code =
M.code;
/* Video search for customers */
SELECT V.title, V.year, V.director, V.rating
(SELECT COUNT(*)
FROM VideoMedia VM
WHERE VM.ID = V.ID AND VM.code = 1) AS num_available
FROM Video V
WHERE V.title LIKE '%<user input>%' AND V.year <= <user input> AND V.year <= <user
input>
AND V.director LIKE '%<user input>%' AND V.rating >= <user input>;
/* Find all copies of a video (used for placing holds or viewing detailed
information). */
SELECT VM.media_id, S.description,
nvl((SELECT SI.name
FROM Stored_In SI
WHERE SI.media_id = VM.media_id), 'none') AS name
FROM VideoMedia VM, Media M, Status S
WHERE VM.title = <user input> AND VM.year = <user input> AND
M.media_id = VM.media_id AND S.code = M.code;
/* Find the status of a given media item */
SELECT S.description
FROM Status S, Media M
BM.ISBN
AND SI.media_id = H.media_id
UNION
SELECT V.title, V.director, V.year, VM.media_id, H.until, H.queue, SI.name
FROM Hold H, VideoMedia VM, Book B, Stored_In SI
INSERT INTO Customer(ID, name, addr, DOB, phone, username, password) VALUES
(<user input>, <user input>, <user input>, <user input>, <user input>,
<user input>, <user input>, );
/* Find a customer */
SELECT C.ID, C.name, C.addr, C.DOB, C.phone, C.username,
nvl((SELECT 'Librarian'
FROM Librarian L
WHERE L.ID = C.ID), 'Customer') AS role
FROM Customer C
WHERE C.username = <user input> AND C.name LIKE '%<user input>%';
/* Add new card and assign it to a customer */
INSERT INTO Card(num, fines, ID) VALUES ( <user input>, 0, <user input>);
/* Create an entry in Checkout */
DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 100
JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering
UPDATE Card
SET fines = <user input>
WHERE num = <user input>
RESULT:
Thus library information system was designed and implemented successfully.
DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 101
JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering
EXPERIMENT NO. 9
Description:
Steps:
4. Click add button and select oracle in ORA home 90, click finish
5. A window will appear given the data source home as oracle and select TNS source name as
lion and give the used id as SWTT
7. The above procedure must be follow except the table , A select the table as library
8. Write appropriate Program in form each from created in VB from each from created in VB
form project.
i. ADMINISTRATOR Table
This table holds the profile information of the application super users otherwise known as
system administrators. They have control of the software meaning that they can perform
additional tasks that other users cannot ordinarily perform. Every software of this nature has
DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 102
JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering
such users and this one is no exception. The table contains the following columns;
ADMIN_ID, TITLE, FRIST_NAME, LAST_NAME, and DEPARMENT_ID. The column
ADMIN_ID is the primary key column (primary key disallows duplicate values and nulls in a
column) every table should have a primary key column, as this acts like table indexing.
v. APP_USER_S Table
This table contains application login details for application students. The table columns are;
USRNAME, PASSWD and MATRIG_NO. The column MATRIG_NO is the primary key
column.
DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 103
JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering
This is more like the main table in the database as all other tables relate to this table directly
or in some other way. This table holds students examination records. The table contains the
following columns; GRADES_ID, SESSION1, REG_NUMBER, DEPARTMENT_ID,
LEVEL1, MATRIG_NO, FRIST_NAME, LAST_NAME, COURCE_CODE, GRADE,
CREDIT_UNIT, SCORE, LECTURER_ID and GRADE_POINT. The column GRADES_ID
is the primary key column.
This table holds the profile information of the application lecturers. The table contains the
following columns; LECTURER_ID, TITLE, FRIST_NAME, LAST_NAME, and
DEPARMENT_ID. The column LECTUTER_ID is the primary key column.
This table contains student‟s registration details i.e. if a student is registered for the semester
this table is used to store that information. The table contains the following columns;
REG_ID, REG_NUMBER, MATRIG_NO, FRIST_NAME, LAST_NAME,LEVEL1,
DEPARTMENT_ID and SESSION1. The column REG_ID is the primary key column.
x. STUDENTS Table
This table holds the profile information of the application students. The table contains the
following columns; MATRIG_NO, TITLE, FRIST_NAME, LAST_NAME, and
DEPARMENT_ID. The column MATRIG_NO is the primary key column.
DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 104
JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering
DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 105
JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering
RESULT:
Thus the student information system was designed and implemented successfully.
DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 106
JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering
EXPERIMENT NO. 10
Description:
Because data is the heart of the enterprise, it's crucial to protect it. And to protect
organization's data, one need to implement a data backup and recovery plan. Backing up files
can protect against accidental loss of user data, database corruption, hardware failures, and
even natural disasters. It's our job as an administrator to make sure that backups are
performed and that backup tapes are stored in a secure location.
Data backup is an insurance plan. Important files are accidentally deleted all the time.
Mission-critical data can become corrupt. Natural disasters can leave office in ruin. With a
solid backup and recovery plan, one can recover from any of these.
It takes time to create and implement a backup and recovery plan. We'll need to figure out
what data needs to be backed up, how often the data should be backed up, and more. To help
we create a plan, consider the following:
How important is the data on systems? The importance of data can go a long way in
helping to determine if one need to back it up—as well as when and how it should be
backed up. For critical data, such as a database, one'll want to have redundant backup
sets that extend back for several backup periods. For less important data, such as daily
user files, we won't need such an elaborate backup plan, but 'll need to back up the data
regularly and ensure that the data can be recovered easily.
What type of information does the data contain? Data that doesn't seem important to we
may be very important to someone else. Thus, the type of information the data contains
DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 107
JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering
can help we determine if we need to back up the data—as well as when and how the
data should be backed up.
How often does the data change? The frequency of change can affect our decision on
how often the data should be backed up. For example, data that changes daily should be
backed up daily.
How quickly do we need to recover the data? Time is an important factor in creating a
backup plan. For critical systems, we may need to get back online swiftly. To do this,
we may need to alter our backup plan.
Who will be responsible for the backup and recovery plan? Ideally, someone should be
a primary contact for the organization's backup and recovery plan. This person may also
be responsible for performing the actual backup and recovery of data.
What is the best time to schedule backups? Scheduling backups when system use is as
low as possible will speed the backup process. However, we can't always schedule
backups for off-peak hours. So we'll need to carefully plan when key system data is
backed up.
Do we need to store backups off-site? Storing copies of backup tapes off-site is essential
to recovering our systems in the case of a natural disaster. In our off-site storage
location, we should also include copies of the software we may need to install to
reestablish operational systems.
DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 108
JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering
There are many techniques for backing up files. The techniques use will depend on the type
of data we're backing up, how convenient we want the recovery process to be, and more.
If we view the properties of a file or directory in Windows Explorer, we'll note an attribute
called Archive. This attribute often is used to determine whether a file or directory should be
backed up. If the attribute is on, the file or directory may need to be backed up. The basic
types of backups we can perform include
Normal/full backups All files that have been selected are backed up, regardless of the
setting of the archive attribute. When a file is backed up, the archive attribute is cleared.
If the file is later modified, this attribute is set, which indicates that the file needs to be
backed up.
Copy backups All files that have been selected are backed up, regardless of the setting
of the archive attribute. Unlike a normal backup, the archive attribute on files isn't
modified. This allows us to perform other types of backups on the files at a later date.
Differential backups Designed to create backup copies of files that have changed since
the last normal backup. The presence of the archive attribute indicates that the file has
been modified and only files with this attribute are backed up. However, the archive
attribute on files isn't modified. This allows to perform other types of backups on the
files at a later date.
Incremental backups Designed to create backups of files that have changed since the
most recent normal or incremental backup. The presence of the archive attribute
indicates that the file has been modified and only files with this attribute are backed up.
When a file is backed up, the archive attribute is cleared. If the file is later modified, this
attribute is set, which indicates that the file needs to be backed up.
Daily backups Designed to back up files using the modification date on the file itself. If
a file has been modified on the same day as the backup, the file will be backed up. This
technique doesn't change the archive attributes of files.
In we backup plan we'll probably want to perform full backups on a weekly basis and
DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 109
JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering
supplement this with daily, differential, or incremental backups. We may also want to create
an extended backup set for monthly and quarterly backups that includes additional files that
aren't being backed up regularly.
Tip We'll often find that weeks or months can go by before anyone notices that a file or data
source is missing. This doesn't mean the file isn't important. Although some types of data
aren't used often, they're still needed. So don't forget that we may also want to create extra
sets of backups for monthly or quarterly periods, or both, to ensure that we can recover
historical data over time.
Once we determine what data we're going to back up and how often, we can select backup
devices and media that support these choices. These are covered in the next section.
Many tools are available for backing up data. Some are fast and expensive. Others are slow
but very reliable. The backup solution that's right for our organization depends on many
factors, including
Capacity The amount of data that we need to back up on a routine basis. Can the backup
hardware support the required load given our time and resource constraints?
Reliability The reliability of the backup hardware and media. Can we afford to sacrifice
reliability to meet budget or time needs?
DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 110
JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering
Extensibility The extensibility of the backup solution. Will this solution meet our needs
as the organization grows?
Speed The speed with which data can be backed up and recovered. Can we afford to
sacrifice speed to reduce costs?
Cost The cost of the backup solution. Does it fit into our budget?
Capacity, reliability, extensibility, speed, and cost are the issues driving our backup plan. If
we understand how these issues affect our organization, we'll be on track to select an
appropriate backup solution. Some of the most commonly used backup solutions include
Tape drives Tape drives are the most common backup devices. Tape drives use
magnetic tape cartridges to store data. Magnetic tapes are relatively inexpensive but
aren't highly reliable. Tapes can break or stretch. They can also lose information over
time. The average capacity of tape cartridges ranges from 100 MB to 2 GB. Compared
with other backup solutions, tape drives are fairly slow. Still, the selling point is the low
cost.
Digital audio tape (DAT) drives DAT drives are quickly replacing standard tape drives
as the preferred backup devices. DAT drives use 4 mm and 8 mm tapes to store data.
DAT drives and tapes are more expensive than standard tape drives and tapes, but they
offer more speed and capacity. DAT drives that use 4 mm tapes can typically record
over 30 MB per minute and have capacities of up to 16 GB. DAT drives that use 8 mm
tapes can typically record more than 10 MB per minute and have capacities of up to 36
GB (with compression).
Auto-loader tape systems Auto-loader tape systems use a magazine of tapes to create
extended backup volumes capable of meeting the high-capacity needs of the enterprise.
With an auto-loader system, tapes within the magazine are automatically changed as
needed during the backup or recovery process. Most auto-loader tape systems use DAT
DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 111
JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering
tapes. The typical system uses magazines with between 4 and 12 tapes. The main
drawback to these systems is the high cost.
Magnetic optical drives Magnetic optical drives combine magnetic tape technology with
optical lasers to create a more reliable backup solution than DAT. Magnetic optical
drives use 3.5-inch and 5.25-inch disks that look similar to floppies but are much
thicker. Typically, magnetic optical disks have capacities of between 1 GB and 4 GB.
Tape jukeboxes Tape jukeboxes are similar to auto-loader tape systems. Jukeboxes use
magnetic optical disks rather than DAT tapes to offer high-capacity solutions. These
systems load and unload disks stored internally for backup and recovery operations.
Their key drawback is the high cost.
Removable disks Removable disks, such as Iomega Jaz, are increasingly being used as
backup devices. Removable disks offer good speed and ease of use for a single drive or
single system backup. However, the disk drives and the removable disks tend to be
more expensive than standard tape or DAT drive solutions.
Disk drives Disk drives provide the fastest way to back up and restore files. With disk
drives, you can often accomplish in minutes what takes a tape drive hours. So when
business needs mandate a speedy recovery, nothing beats a disk drive. The drawbacks
to disk drives, however, are relatively high costs and less extensibility.
Before we can use a backup device, we must install it. When we install backup devices other
than standard tape and DAT drives, we need to tell the operating system about the controller
card and drivers that the backup device uses. For detailed information on installing devices
and drivers, see the section of Chapter 2 entitled "Managing Hardware Devices and Drivers."
Selecting a backup device is an important step toward implementing a backup and recovery
plan. But we also need to purchase the tapes or disks, or both, that will allow we to
implement our plan. The number of tapes we need depends on how much data we'll be
DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 112
JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering
backing up, how often we'll be backing up the data, and how long we'll need to keep
additional data sets.
The typical way to use backup tapes is to set up a rotation schedule whereby we rotate
through two or more sets of tapes. The idea is that we can increase tape longevity by reducing
tape usage and at the same time reduce the number of tapes we need to ensure that we have
historic data on hand when necessary.
One of the most common tape rotation schedules is the 10-tape rotation. With this rotation
schedule, we use 10 tapes divided into two sets of 5 (one for each weekday). As shown in
Table 14-2, the first set of tapes is used one week and the second set of tapes is used the next
week. On Fridays, full backups are scheduled. On Mondays through Thursdays, incremental
backups are scheduled. If we add a third set of tapes, we can rotate one of the tape sets to an
off-site storage location on a weekly basis.
Tip The 10-tape rotation schedule is designed for the 9 to 5 workers of the world. If we're in a
24 x 7 environment, we'll definitely want extra tapes for Saturday and Sunday. In this case,
use a 14-tape rotation with two sets of 7 tapes. On Sundays, schedule full backups. On
Mondays through Saturdays, schedule incremental backups.
RESULT:
DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 113
JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering
EXPERIMENT NO. 11
Description:
A transaction is a unit of work that is performed against a database. Transactions are units or
sequences of work accomplished in a logical order, whether in a manual fashion by a user or
automatically by some sort of a database program.
A transaction is the propagation of one or more changes to the database. For example, if you
are creating a record or updating a record or deleting a record from the table, then you are
performing transaction on the table. It is important to control transactions to ensure data
integrity and to handle database errors.
Properties of Transactions:
Transactions have the following four standard properties, usually referred to by the acronym
ACID:
Atomicity: ensures that all operations within the work unit are completed
successfully; otherwise, the transaction is aborted at the point of failure, and previous
operations are rolled back to their former state.
Consistency: ensures that the database properly changes states upon a successfully
committed transaction.
Isolation: enables transactions to operate independently of and transparent to each
other.
Durability: ensures that the result or effect of a committed transaction persists in
case of a system failure.
DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 114
JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering
Query: Consider a table Employee with a few records in it. Write a PL/SQL code to insert a
new record into the table Employee, and then update the salary of the employee newly
inserted. Delete the same updated record.
Now find the outputs in the case of
(1)Complete Rollback
(2)Partial Rollback
(3)Transaction Committed.
SQL>select * from emp018;
EMPNO EMPNAME DESIGNATION SALARY
e1 Charu HR 50000
e3 Ankita Marketting 60000
e4 jai Finance 50000
e5 Anil Sales 10000
e6 Shivani Sales 70000
5 rows selected
PL/SQL Code
SQL>set serveroutput on
SQL>declare
en varchar(10);
desig char(15);
name char(10);
sal number;
begin
en:=&en;
desig=&design;
name=&name;
DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 115
JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering
sal=&sal;
insert into emp018 values(en, design,name,sal);
update emp018 set salary=salary+1000 where empno=en;
savepoint new1;
delete from emp018 where empno=en;
end;
Enter the value for en: ‗e7‘
old 7:en=&en;
new 7:en=‘e7‘;
Enter the value for design:‘analyst‘
old 8:design=&design;
new 8: design=‘analyst‘;
Enter the value for name:‘Meenakshi‘
old 9: name=&name;
new 9:name=‘Meenakshi‘;
Enter value for sal: 5900
old 10: sal=&sal;
new 10: sal=5900;
PL/SQL procedure successfully completed.
Complete Rollback:
SQL> rollback
Rollback complete.
SQL>select * from emp018;
EMPNO EMPNAME DESIGNATION SALARY
e1 Charu HR 50000
e3 Ankita Marketting 60000
e4 jai Finance 50000
e5 Anil Sales 10000
e6 Shivani Sales 70000
5 rows selected
DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 116
JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering
Partial Rollback
SQL>rollback to new1;
Rollback complete.
e1 Charu HR 50000
e3 Ankita Marketting 60000
e4 jai Finance 50000
e5 Anil Sales 10000
e6 Shivani Sales 70000
e7 Meenakshi Analyst 5900
6 rows selected
COMMIT
SQL>commit;
Commit Complete.
SQL>select * from emp018;
EMPNO EMPNAME DESIGNATION SALARY
e1 Charu HR 50000
e3 Ankita Marketting 60000
e4 jai Finance 50000
e5 Anil Sales 10000
e6 Shivani Sales 70000
5 rows selected
DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 117
JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering
SAVEPOINT:
It is used for restore the database to certain previous state for which
certain DML statements are undone.
Example:
savepoint D1;
delete from emp where ename='Scott';
savepoint D2;
selete from emp where ename='King';
rollback D2;
commit;
Post-Experiment Questions:
DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 118
JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering
APPENDIX
AKTU SYLLABUS
KCS-551: DATABASE MANAGEMENT SYSTEMS LAB
DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 119
JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering
DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 120