0% found this document useful (0 votes)
14 views

DBMS Lab Manual

The document is a laboratory manual for the Database Management Systems (DBMS) course at JSS Academy of Technical Education, outlining the vision and mission of the institute and department, along with program educational outcomes, program outcomes, and specific course outcomes. It includes a list of experiments designed to enhance students' practical skills in database design and SQL queries, as well as guidelines for laboratory conduct and safety instructions. The manual aims to provide students with a comprehensive understanding of DBMS applications and operations.

Uploaded by

padaikarog
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

DBMS Lab Manual

The document is a laboratory manual for the Database Management Systems (DBMS) course at JSS Academy of Technical Education, outlining the vision and mission of the institute and department, along with program educational outcomes, program outcomes, and specific course outcomes. It includes a list of experiments designed to enhance students' practical skills in database design and SQL queries, as well as guidelines for laboratory conduct and safety instructions. The manual aims to provide students with a comprehensive understanding of DBMS applications and operations.

Uploaded by

padaikarog
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 120

JSS MAHAVIDYAPEETHA

LABORATORY MANUAL

Subject Name: DBMS LAB

Subject Code: KCS-551


COURSE : B.Tech SEMESTER : V SEM

Name

Roll No.

Section-Batch

Department of Computer Science and Engineering


JSS ACADEMY OF TECHNICAL EDUCATION
C-20/1, SECTOR-62, NOIDA
JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

VISION OF THE INSTITUTE

JSS Academy of Technical Education Noida aims to become an Institution of excellence in


imparting quality Outcome Based Education that empowers the young generation with
Knowledge, Skills,Research, Aptitude and Ethical values to solve Contemporary
Challenging Problems.

MISSION OF THE INSTITUTE

 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.

 Provide an environment for acquiring ethical values and positive attitude.

VISION OF THE DEPARTMENT


To spark the imagination of the Computer Science Engineers with values, skills and
creativity to solve the real world problems.

MISSION OF THE DEPARTMENT

 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.

PROGRAM EDUCATIONAL OUTCOMES (PEOs)


PEO1: To empower students with effective computational and problem solving skills.
PEO2: To enable students with core skills for employment and entrepreneurship.
PEO3: To imbibe students with ethical values and leadership qualities.
PEO4: To foster students with research oriented ability which helps them in analyzing and
solving real life problems and motivate them for pursuing higher studies.

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 2


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

PROGRAM OUTCOMES (POs)

Engineering Graduates will be able to:

PO1: Engineering knowledge: Apply the knowledge of mathematics, science,


engineering fundamentals, and an engineering specialization to the solution of
complex engineering problems.

PO2: Problem analysis: Identify, formulate, review research literature, and


analyze complex engineering problems reaching substantiated conclusions using
first principles of mathematics, natural sciences, and engineering sciences.

PO3: Design/development of solutions: Design solutions for complex


engineering problems and design system components or processes that meet the
specified needs with appropriate consideration for the public health and safety, and
the cultural, societal, and environmental considerations.

PO4: Conduct investigations of complex problems: Use research-based


knowledge and research methods including design of experiments, analysis and
interpretation of data, and synthesis of the information to provide valid conclusions.

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.

PO7: Environment and sustainability: Understand the impact of the professional


engineering solutions in societal and environmental contexts, and demonstrate the
knowledge of, and need for sustainable development.
PO8: Ethics: Apply ethical principles and commit to professional ethics and
responsibilities and norms of the engineering practice.

PO9: Individual and team work: Function effectively as an individual, and as a


member or leader in diverse teams, and in multidisciplinary settings.

PO10: Communication: Communicate effectively on complex engineering activities


with the engineering community and with society at large, such as, being able to

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 3


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

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.

PROGRAM SPECIFIC OUTCOMES (PSOs)


PSO1: An ability to apply foundation of Computer Science and Engineering, algorithmic
principles and theory in designing and modeling computation based systems.

PSO2: The ability to demonstrate software development skills.

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 4


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

COURSE OUTCOMES (COs)

SL.NO DESCRIPTION COGNITIVE


LEVEL (BLOOMS
TAXONOMY)
Understand and apply oracle 11 g products for creating tables, K2, K4
C308.1 views, indexes, sequences and other database objects.
Design and implement a database schema for company data base, K3, K5, K6
C308.2 banking data base, library information system, payroll processing
system, student information system.
Write and execute simple and complex queries using DDL, DML, K4, K5
C308.3 DCL and TCL
Write and execute PL/SQL blocks, procedure functions, packages K4, K5
C308.4 and triggers, cursors.
Enforce entity integrity, referential integrity, key constraints, and K3, K4
C308.5 domain constraints on database.

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

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 5


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

LIST OF EXPERIMENTS

Sr. No. Title of experiment Corresponding CO


1 Write the queries for Data Definition and Data C308.3
Manipulation Language.
2 To explore ‗select‘ statement using various clauses C 308.3
like where, order by, between, like, group by, having
and logical/relational operator. To implement various
DML statements
3 To implement nested and correlated queries and to C 308.1
create various views and indexes
4 To enforce various integrity constraint and to C 308.3, C 308.5
implement various DCL statements.
5 To implement Cursors and triggers using PL/SQL. C 308.4
6 To implement Procedures and Functions using C 308.4
PL/SQL.
7 Design and implementation of payroll processing C 308.2
systems.
8 Design and implementation of Library Information C 308.2
systems.
9 Design and implementation of Student Information C 308.2
systems.
10 C308.1,C308.2, C308.3,
Automatic Backup of Files and Recovery of Files C308.4, C 308.5
11 Mini Project (Design and Development of Data & C308.1,C308.2, C308.3,
Application) as Per AKTU Curriculum – Refer C308.4, C 308.5
Appendix
Content beyond syllabus (not limited to two)
12 To implement various TCL commands C308.3

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 6


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

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

A trigger is an application which consists of event, condition, and action in an organized


manner. It will be activated only when there is some insertion, deletion or modification of
content present in database. There are 2 types of triggers row-level trigger and statement level
trigger.

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 7


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

Applications of DBMS

1. Data independence
2. Efficient data access
3. Data integrity
4. Data security
5. Concurrent access
6. Crash recovery.

Some Examples of DBMS are:

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.

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 8


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

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.

Dr. Kakoli Banerjee

Associate Professor, Dept. of CSE

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 9


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

DO’S AND DONT’S

DO’s

1. Conform to the academic discipline of the department.


2. Enter your credentials in the laboratory attendance register.
3. Read and understand how to carry out an activity thoroughly before coming to the
laboratory.
4. Ensure the uniqueness with respect to the methodology adopted for carrying out the
experiments.
5. Shut down the machine once you are done using it.

DONT’S

1. Eatables are not allowed in the laboratory.


2. Usage of mobile phones is strictly prohibited.
3. Do not open the system unit casing.
4. Do not remove anything from the computer laboratory without permission.
5. Do not touch, connect or disconnect any plug or cable without your faculty/laboratory
technician‘s permission.

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 10


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

GENERAL SAFETY INSTRUCTIONS

1. Know the location of the fire extinguisher and the first aid box and how to use them in
case of an emergency.

2. Report fires or accidents to your faculty /laboratory technician immediately.

3. Report any broken plugs or exposed electrical wires to your faculty/laboratory


technician immediately.

4. Do not plug in external devices without scanning them for computer viruses.

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 11


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

DETAILS OF THE EXPERIMENTS CONDUCTED

(TO BE USED BY THE STUDENTS IN THEIR RECORDS)


MARKS FACULTY
DATE OF EXPT. TITLE OF THE PAGE
S.No AWARDED SIGNATURE
CONDUCTION No EXPERIMENT No.
(20) WITH REMARK

10

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 12


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

GUIDELINES FOR LABORTORY RECORD PREPARATION

While preparing the lab records, the student is required to adhere to the following guidelines:

Contents to be included in Lab Records:


1. Cover page
2. Vision
3. Mission
4. PEOs
5. POs
6. PSOs
7. COs
8. CO-PO-PSO mapping
9. Index
10. Experiments
 Aim
 Source code
 Input-Output

A separate copy needs to be maintained for pre-lab written work


The student is required to make the Lab File as per the format given on the next two pages.

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 13


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

JSS ACADEMY OF TECHNICAL EDUCATION

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

DATABASE MANAGEMENT SYSTEM LAB FILE (KCS 551)

Name

Roll No.

Section- Batch

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 14


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

INDEX
Experiment Experiment Date of Date of Faculty
No. Name Conduction Submission Signature

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 15


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 16


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

GUIDELINES FOR ASSESSMENT

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.

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 17


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

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.

Pre- Experiment Questions:


Q.1 What are the commands under DDL?
Q.2 List commands under DML?
Q.3 Define the Syntax for CREATE Table command.
Q.4 What are the key features to distinguish primary key from foreign key?

Write queries for creating the following tables:

STUDENT (Roll_No, Name, Branch, Year, Section, Hostel, F _name, Address)


BOOK (Book_id, Title, Author, Publisher, Cost, Copies)
TRANSACTION (Roll_No, Book_Id, Date_Issue, Date_Return, Fine)
Add Primary Key and Foreign key to appropriate attributes in the above mentioned
tables. Add a constraint on Book table for accepting value in Copies attribute not less
than 0.

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 18


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

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.

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 19


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

Describe the tables.


Query: Display the structure of the tables.
Syntax: desc tablename;
SQL Command:
SQL> desc empl018;
Output:
Name Null? Type

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)

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 20


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

Insertion into Table

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

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 21


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

Enter value for city: Bangalore


Enter value for salary: 40000
Enter value for deptno: d4
old 1: insert into empl018 values('&empno','&empname','&job','&city','&salary','&deptno')
new 1: insert into empl018 values('e4','jai','Finance','Bangalore','40000','d4')
Output:
1 row created.

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.

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 22


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

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

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 23


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

Enter value for dname: cse


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('d1','cse','Delhi','p1')
Output:
1 row created.

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.

Display the tables.


Query:Select and display the records of the tables employee, project and department.

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 24


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

Syntax: select * from tablename;

SQL Command:
SQL> select * from empl018;
Output:

EMPNO EMPNAME JOB CITY SALARY DEPTN


-
e1 Charu HR Agra 50000 d1
e2 Meenamkshi IT Jhansi 40000 d2
e3 Ankita Marketting Delhi 60000 d3
e4 jai Finance Bangalore 40000 d4
e5 Anil Sales Bangalore 10000 d5
e6 Shivani Sales Bangalore 70000 d6
6 rows selected.

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

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 25


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

Display selected columns and all rows.


Query: Display only employee no. and employee name from the table employee.
Syntax: select attr1, attr2,……… from table name;
SQL Command: SQL> select empno,empname from empl018;
Output:
EMPNO EMPNAME

e1 Charu
e2 Meenamkshi
e3 Ankita
e4 jai
e5 Anil
e6 Shivani
6 rows selected.
Add a column.

Query: Add a column age to table employee.


Syntax: alter table tablename add(columnname type(size));
SQL Command:
SQL> alter table empl018 add(age number(3));
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)
AGE NUMBER(3)

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 26


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

Insert value in the table.


Query: Insert value into the new column age.
Syntax: insert into tablename(atrr1, attr2,……)values(v1, v2……);
SQL Command:
SQL> insert into empl018(age)values(20);
Output:
1 row created.
SQL> select * from empl018;

EMPNO EMPNAME JOB CITY SALARY DEPTN AGE

e1 Charu HR Agra 50000 d1


e2 Meenamkshi IT Jhansi 40000 d2
e3 Ankita Marketting Delhi 60000 d3
e4 jai Finance Bangalore 40000 d4
e5 Anil Sales Bangalore 10000 d5
e6 Shivani Sales Bangalore 70000 d6
7 rows selected.

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)

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 27


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

SALARY NUMBER(10)
DEPTNO VARCHAR2(5)

Modify the existing datatype.


Query: Modify the attribute employee name by changing its datatype to varchar.
Syntax: alter table tablename modify(attrname newtype(size));
SQL Command:
SQL> alter table empl018 modify(empname varchar(15));
Output:
Table altered.
SQL> desc empl018;
Name Null? Type

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.

Query: Create a fake table with a row in it and truncate it.


Syntax: truncate table tablename;
SQL Command:
SQL> create table faketble(sno varchar(2), name char(10));

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 28


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

Table created.
SQL> insert into faketble values('1','mini');
1 row created.
SQL> select * from faketble;
SN NAME

1 mini

SQL> truncate table faketble;


Output:
Table truncated.
SQL> select * from faketble;
no rows selected

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

Update the table


Query: Update the salary of employee by 1.25%.
Syntax: update tablename set updation where condition
SQL Command:
SQL> update emp018 set salary=salary*1.25 where salary=40000;
Output:
2 rows updated.
SQL> select * from emp018;

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 29


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

EMPNO EMPNAME JOB CITY SALARY DEPTN

e1 Charu HR Agra 50000 d1


e2 Meenamkshi IT Jhansi 50000 d2
e3 Ankita Marketting Delhi 60000 d3
e4 jai Finance Bangalore 50000 d4
e5 Anil Sales Bangalore 10000 d5
e6 Shivani Sales Bangalore 70000 d6
7 rows selected.

Delete the table.


Query: Delete the record from employee whose employee no. is e2.
Syntax: delete from tablename where condition;
SQL Command:
SQL> delete from emp018 where empno='e2';
Output:
1 row deleted.
SQL> select * from emp018;
EMPNO EMPNAME JOB CITY SALARY DEPTN

e1 Charu HR Agra 50000 d1


e3 Ankita Marketting Delhi 60000 d3
e4 jai Finance Bangalore 50000 d4
e5 Anil Sales Bangalore 10000 d5
e6 Shivani Sales Bangalore 70000 d6
6 rows selected.

SQL> commit;
Commit complete.
SQL> spool off;

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 30


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

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?

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 31


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

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.

Pre- Experiment Questions:


Q.1 What are the commands under DML?
Q.2 What does select command do?
Q.3 Define the Syntax for CREATE Table command.
Q.4 What are relational operators and how they can be used?

Write Syntax for creating the following tables:


Write SQL command to add a new field DOB in the STUDENT table.
Input
SQL> alter table STUDENT add DOB date;
Output
Table altered.
Write SQL command to drop Fine column from TRANSACTION table.
Input
SQL> alter table TRANSACTION drop column FINE;
Output
Table altered.
Insert at least 5 records in each table.
Input
SQL> insert into STUDENT values(&Roll_No, &Name, &Branch, &Year, &Section,
&Hostel,&F_name, &Address);
Enter value for Roll_No: 1209113053
Enter value for Name: 'Roffery'

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 32


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

Enter value for Branch:‘CS‘


Enter value for Year: 4
Enter value for Section: ‗CS-1‘
Enter value for Hostel: ‗Sanskriti‘
Enter value for F_name: ‗John‘
Enter value for Address: ‗12/45 Lajapt Nagar, Delhi‘
old 1: insert into STUDENT values(&Roll_No, &Name, &Branch, &Year, &Section,
&Hostel,&F_name, &Address)
new 1: insert into STUDENT values(1209113053, 'Roffery',‘CS‘,4,‘CS-1‘, ‗Sanskriti‘,
‗John‘, ‗12/45 Lajapt Nagar, Delhi‘)
Output
1 row created.
Input
SQL> /
Enter value for Roll_No: 1209113073
Enter value for Name: 'Ron'
Enter value for Branch:‘EC‘
Enter value for Year: 4
Enter value for Section: ‗EC-2‘
Enter value for Hostel: ‗Sanskriti‘
Enter value for F_name: ‗Jay‘
Enter value for Address: ‗12/85 Sec-67, Noida‘
old 1: insert into STUDENT values(&Roll_No, &Name, &Branch, &Year, &Section,
&Hostel,&F_name, &Address)
new 1: insert into STUDENT values(1209113059, 'Ron',‘EC‘,4,‘EC-2‘, ‗Sanskriti‘, ‗Jay‘,
‗12/85 Sec-67,Noida‘)
Output
1 row created.
Input
SQL> / (Rest other entries, try yourself)
Input
SQL> insert into BOOK values(‗BB-095‘, 'Database Management System',
Korth,Schilberschutz‘ , ‘TATA Mc-Graw‘, 1595.56,300);

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 33


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

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:

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 34


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

select attrname from tablename where condition;


SQL COMMAND:
SQL> select empname from emp018 where city!='Jhansi';
OUTPUT:
EMPNAME

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

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 35


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

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

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 36


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

Display selected rows and all columns.


QUERY: Display the records of those whose salary is 50,000.
SYNTAX:
Select * from tablename where condition;
SQL COMMAND:
SQL> select * from emp018 where salary=50000;
OUTPUT:
EMPNO EMPNAME JOB CITY SALARY DEPTN

e1 Charu HR Agra 50000 d1


e4 jai Finance Bangalore 50000 d4
SQL> commit;
Commit complete.
SQL> spool off;

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

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 37


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

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

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 38


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

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.

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 39


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

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.

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 40


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

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.

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 41


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

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

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 42


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

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.

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 43


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

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;

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 44


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

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;

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 45


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

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)

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 46


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

-.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

Title: tan function.


Query23: display the sine value of 92.
Syntax: select tan(number)from dual;
Command:
SQL> select tan(92)from dual;

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

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 47


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

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

Last date function


Query27: display the Last date when the database is stored
Syntax: select last_day(sysdate) from dual;
Command:
SQL> select last_day(sysdate)from dual;
Output:
LAST_DAY(

29-FEB-12

Sysdate function
Query28: display the system date when the database is stored

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 48


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

Syntax: select sysdate from dual;


Command:
SQL> select sysdate from dual;
Output:
SYSDATE

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;

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 49


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

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;

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 50


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

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?

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 51


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

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..

Pre- Experiment Questions:


Q.1 What is the difference between delete and drop command?
Q.2 Why do we use update command?
Q.3 Define nested queries.
Q.4 What is a view?

Update title of books from 'Database Management Systems' to 'DBMS'.


Input
SQL> update BOOK set Title=‘DBMS‘ where Title='Database Management Systems' ;
Output
1 rows updated.

Delete all entries from the Hostel column of STUDENT table.


Input
SQL> update STUDENT set Hostel=NULL;
Output
5 rows updated.
Write SQL Queries for the following:
Input
(a) To display the details of all students.
SQL> select * from STUDENT;

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 52


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

(b) Display the records of (a) in ascending order of Roll_No.


SQL> select * from STUDENT
order by Roll_No;
(c) To display all Networking Books in the Library.
SQL> select * from BOOK
where Title = ‗Networking‘;
(d) To display those books which have 'Computer' word in their title (like Computer
Fundamentals, Computer Graphics etc.).
SQL> select * from BOOK
where Title like ‗Computer%‘;
(e) To display all the books which have been issued so far.
SQL> select * from BOOK b
where b.Book_id = TRANSACTION.Book_id;
(f) To display the books which have not been issued so far.
SQL> select * from BOOK
where BOOK.Book_id NOT IN (select Book_id from BOOK b
where b.Book_id = TRANSACTION.Book_id);
(g) To display all the students of 4th year CSE branch who are staying in Hostel.
SQL> select * from STUDENT
where Hostel IS NOT NULL and Year=4 and Branch=‘CSE‘ ;
(h) To display the student's names who have not returned the books issued to them.
SQL> select Name from STUDENT S, TRANSACTION T, DUAL D
where S.Roll_No=T.Roll_No and (T.Date_Return< D.getdate( ) OR T.Date_Return IS
NULL);
(i) To display the student names that have been issued DBMS book by Korth.
SQL> select Name from STUDENT S, TRANSACTION T, BOOK B
where S.Roll_No=T.Roll_No and T.Book_id=B.Book_id
and B.Title=‘DBMS‘ and B.Author=‘Korth‘;
(j) To display the students who have not issued any book so far.
SQL> select * from STUDENT S
where S.Roll_No NOT IN ( select Roll_No from TRANSACTION T
where S.Roll_No=T.Roll_No );
(k) To display the students who have been issued at least one book.

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 53


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

SQL> select * from STUDENT S


where EXISTS ( select Roll_No from TRANSACTION);
(l) To display the title of the second costliest book.
SQL> select Title from
(select Title from BOOK order by Cost )
where ROWNUM=2;
(m) To display the students who have not returned the book more than 6 weeks.
SQL> select * from STUDENT S, TRANSACTION T
where S.Roll_No=T.Roll_No and T.Date_Return - T.Date_Issue >=42;
(n) To display the student names along with all the books issued to them.
SQL> select Name, Book_id from STUDENT S, TRANSACTION T, BOOK B
where S.Roll_No=T.Roll_No and T.Book_id=B.Book_id
Group by S.Roll_No;
(o) To display the students of IV year from CSE branch who have been issued Graphics
book(s) for more than 15 days, which have not been returned.
SQL> select * from STUDENT S, TRANSACTION T, DUAL D , BOOK B
where S.Roll_No=T.Roll_No and T.Book_id=B.Book_id
and D.sysdate - T.Date_Issue>=15 and B.Title like‘%Graphic%‘
and S.Year=4 and S.Branch=‘CSE‘;
Create view to access the student's details only from 4th year of CSE branch.
Input
SQL>Create VIEW CSE_4 (CS_Roll_No, CS_Name, CS_Branch, CS_Year, CS_Section,
CS_Hostel, CS_F_name, CS_Address)
as select * from STUDENT where Year=4 and Branch=‘CSE‘;
Create an index on Title column of BOOK Table.
Input
SQL>Create INDEX My_Index ON BOOK(Title);

Queries Using Join:

Tables:

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 54


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

emp018:
EMPNO EMPNAME JOB CITY SALARY DEPTN MGRNO

e1 Charu HR Agra 50000 d1 e4


e3 Ankita Marketting Delhi 60000 d3 e4
e4 jai Finance Bangalore 50000 d4
e5 Anil Sales Bangalore 10000 d5 e4
e6 Shivani Sales Bangalore 70000 d6 e4

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

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 55


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

p1 e6

Query 1: Get the details of the employees working on ‗p1‘.


Syntax:
select attr1,attr2……. from table 1, table2……where condition1 and condition 2……
SQL Command:
SQL>select empno,empname from emp018,asto018 where emp018.empno=asto018.eno and
pno=‘p1‘;
Output:
EMPNO EMPNAME

e1 Charu
e3 Ankita
e4 jai
e5 Anil
e6 Shivani

Query 2: Get the details of the employees working on p1 and p2.


Syntax:
select attr1, attr2….from table1,table2 where condition)intersect(select attr1,attr2….from
table1,table 2 where condition1 and condition2);
SQL Command:
SQL>(select emp018.empno,emp018.empname from emp018, asto018 where emp018.empno
=asto018.eno and pno='p1') intersect (select emp018.empno,emp018.empname from emp018,
asto018 where emp018.empno=asto018.eno and pno='p2');
SQL> select empno,empname from emp018,asto018 where emp018.empno=asto018.eno and
(pno='p1' or pno='p2');
Output:
EMPNO EMPNAME

e3 Ankita

Query 3: Get the employee number of the employees who are not working on ‗p1‘.

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 56


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

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

Query 4: Perform LEFT OUTER JOIN on table project and assignmedto.


Syntax: select attr1, attr2…… from table1,table2 where table1.attr=table2.attr(+);
SQL Command:
SQL> select projo18.pname, projo18.ename, asto018.eno from projo18,asto018 where
projo18.pno=asto018.pno(+);
Output:
PNAME ENAME ENO

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

PNAME ENAME ENO

DBMS jai e1

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 57


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

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

PNAME ENAME ENO

DBMS anil e5
DBMS anil e6
DBMS anil e4
NW Ankita e3
CO shivani e6
Automata Charu e1
SQL jai e4

29 rows selected.

Query 5: Perform RIGHT OUTER JOIN on table project and assignmedto.


Syntax: select attr1, attr2…… from table1,table2 where table1.attr=table2.attr(+);
SQL Command:
SQL> select projo18.pname, projo18.ename, asto018.eno from projo18,asto018 where
asto018.pno(+)=projo18.pno;
Output:
PNAME ENAME ENO

DBMS Charu e3
DBMS Charu e1

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 58


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

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

PNAME ENAME ENO

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

PNAME ENAME ENO

DBMS anil e5
DBMS anil e6
DBMS anil e4
NW Ankita e3
CO shivani e6
Automata Charu e1
SQL jai e4

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 59


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

29 rows selected.

Query6: Get the details of the employees working on ‗p1‘.


Syntax:
select attr1,attr2……from table1 where ―linking attribute‖ in(select ―linking attribute‖ from
table 2 where condition;

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

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 60


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

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

Using Order By Clause

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;

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 61


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

Output:
PNO ENAME

p1 Charu
p1 Charu
p1 jai
p1 anil
p1 Shivani
p2 Ankita
p4 shivani
p6 Charu
p8 jai

Using Multicolumn subquery

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.

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 62


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

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.

Query2:-Drop the view created in the table myproj.


Syntax:-
Drop view ―viewname‖.
Command:-
SQL> drop view myproj;
Output:-
View dropped.

Union

Query1:-Find the employee who are working on project p11 or p21.


Syntax:-
Select ―columnname‖ from ―tablename‖ where ―condition‖UNION select ―columnname‖
from ―tablename‖ where ―condition‖.

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 63


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

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:-

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 64


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

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.

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 65


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

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.

Query4:-Add unique key to employee name in the existing table.


Syntax:-
Alter table ―Tablename‖ add constraint uk unique(empname).
Command:-
SQL> alter table emp18 add constraint uk unique(empname);
Output:-
Table altered.

Query5:-Drop unique key constraint from employee table.

Syntax:-
Alter table ―Tablename‖ drop constraint uk .
Command:-
SQL> alter table emp18 drop constraint uk;
Output:-
Table altered.

Query6:-Drop primary key constraint from employee table.


Syntax:-
Alter table ―Tablename‖ drop constraint pk .
Command:-
SQL> alter table emp18 drop constraint pk;

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 66


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

Output:-
Table altered.

Query7:-Define empname as foreign key constraint in project table.


Syntax:-
Alter table ―Tablename‖ add constraint fk foreign key(empname) references (empname).
Command:-
SQL> alter table project add constraint fk foreign key(empname) references(empname);
Output:-
Table altered.

Query8:-Drop foreign key constraint from project table.


Syntax:-
Alter table ―Tablename‖ drop constraint fk .
Command:-
SQL> alter table project drop constraint fk;
Output:-
Table altered.

Query9:-Drop the check constraint on salary.


Syntax:-
Alter table ―Tablename‖ drop constraint ck salary .
Command:-
SQL>alter table drop constraint ck salary.
Output:-
Table altered.

Post-Experiment Questions:

Q.1 What is the significance of an index?


Q.2 List two advantages of creating views.
Q.3 What are the key constraints?
Q.4 How restrictions an be implemented on the database?

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 67


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

EXPERIMENT NO. 4

Aim : To enforce various integrity constraint and to implement various DCL


statements.

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.

Pre- Experiment Questions :

Q.1 What is an integrity constraint?


Q.2 Define procedures in PL/SQL?
Q.3 How do we declare variables in PL/SQL program?

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;

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 68


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

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‖

Write PL/SQL program to display 5 costliest books in the library.

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;

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 69


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

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:

SQL> Set Serveroutput on;


SQL> Declare
i number(3);
n number(3);
fact number(5);
Begin
n:=&n;
fact:=1;
i:=n;
whilei>=1
loop
fact:=fact*i;
i:=i-1;
end loop;
DBMS_OUTPUT.PUT_LINE('Value of fact'||fact);

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 70


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

end; /

Output:

Enter value for n: 3


old 6: n:=&n;
new 6: n:=3;
Value of fact6

PL/SQL procedure successfully completed.

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:

SQL> set serveroutput on;


SQL> declare
empno emp018.eno%type;
begin
empno:=&empno;
update emp018
set salary=25000 where eno=empno and salary<20000;
end;

Output:

Enter value for empno: 12


old 4: empno:=&empno;
new 4: empno:=12;

PL/SQL procedure successfully completed.

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 71


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

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?

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 72


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

EXPERIMENT NO. 5

AIM: To Implement Cursors and triggers using PL/SQL.

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.

Pre- Experiment Questions:

Q.1 What is the basic use of a Cursor?


Q.2 What are the different components of a PL/SQL trigger?
Q.3 Explain cursor types?
Q.4 What are the advantages/uses of using triggers?

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.

SQL> select * from employee018;


EMPN ENAME SALARY JOB

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 73


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

e1 Meenakshi 75000 director


e2 Deepak 6500 Analyst
e3 Devesh 7000 Manager
e4 Shashank 2000 Clerk
e5 Shantnu 8000 Manager

PL/SQL code block:

SQL> set serveroutput on


SQL> declare
cursor cl is
select * from employee018 where salary>2500 and job<>'director';
emprec employee018%rowtype;
begin
open cl;
dbms_output.put_line('records fetched are');
if cl%isopen then
loop
fetch cl into emprec;
exit when cl%notfound; dbms_output.put_line(emprec.empn||' '|| emprec.ename||'
'||emprec.salary
||' '||emprec.job);
if emprec.job='Manager'
then
update employee018 set salary=salary+500 where empn=emprec.empn;
elseif emprec.job='analyst' then
update employee018 set salary=salary+750 where empn=emprec.empn;
end if;
end loop;
close cl;
end if;
end;

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 74


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

OUTPUT:
records fetched are

EMPN ENAME SALARY JOB

e2 Deepak 6500 Analyst


e3 Devesh 7000 Manager
e5 Shantnu 8000 Manager

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:

SQL>select * from cust_mast;

CUST CUST_NAME DOB

c1 Meenakshi 26-SEP-91
c2 Shivani 27-DEC-92
c3 Shantanu 30-SEP-72

PL/SQL code block


SQL>set serveroutput on
SQL> create trigger audit_sys before delete or update on cust_mast
for each row
begin
insert into audit_sys values(:old.cust_no,:old.cust_name,:old.dob);
end;
/
Output

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 75


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

Trigger created.

SQL>delete from cust_mast where cust_no=‘c3‘;


1 row deleted.
SQL>select * from audit_sys;
CUST CUST_NAME DOB

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 :

Q.1 What are PL/SQL cursor exceptions?


Q.2 What is the maximum limit of applying Triggers to a Table?
Q.3 What is the method to find out whether a Cursor is open or not?
Q.4 What is the default type of triggers?

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 76


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

EXPERIMENT NO. 6

Aim: To implement Procedure and Fucntions using PL/SQL.

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

A function is same as a procedure except that it returns a value. A standalone function is


created using the CREATE FUNCTION statement While creating a function, you give a
definition of what the function has to do. To use a function, you will have to call that function
to perform the defined task. When a program calls a function, the program control is
transferred to the called function

Pre- Experiment Questions :

Q.1 What is the Difference between a Function and a Stored Procedure?


Q.2 How functions and procedures are called in a PL SQL block?
Q.3 What are character functions?

PROCEDURE TO INSERT NUMBER

SQL> create table emp1(id number(3),First_name varchar2(20));


Table created.

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 77


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

SQL> insert into emp1 values(101,'Nithya');


1 row created.
SQL> insert into emp1 values(102,'Maya');
1 row created.
SQL> select * from emp1;
ID FIRST_NAME

101 Nithya

102 Maya

SQL> set serveroutput on;


SQL> create or replace
procedure insert_num(p_num number)is
begin
insert into emp1(id,First_name) values(p_num,user);
end insert_num;
Procedure created.
SQL> exec insert_num(3);

PL/SQL procedure successfully completed.


SQL> select * from emp1;
ID FIRST_NAME

101 Nithya

102 Maya

103 SCOTT

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 78


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

FUNCTION TO FIND FACTORIAL

SQL> create or replace function fact(n number)


return number is
i number(10);
f number:=1;
begin
for i in 1..N loop
f:=f*i;
end loop;
return f;
end;
Function created.

SQL> select fact(2) from dual;


FACT(2)

RESULT:

Thus procedures and functions were implemented successfully.

PL/SQL PROGRAM FOR BONUS CALCULATION

SQL> set serveroutput on;


SQL> declare
salary number;
bonus number;

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 79


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

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.

PROGRAM FOR ARMSTRONG NUMBER


SQL> set serveroutput on;
SQL> declare
a number;
b number;
i number;
begin
i:=&num;
a:=i;
b:=0;
while a>0 10
loop
b:=b+power(mod(a,10),3);
a:=trunc(a/10);
end loop;
if b=i then
dbms_output.put_line(i||'IS AN ARMSTRONG NUMBER');
else

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 80


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

dbms_output.put_line(i||'IS NOT AN ARMSTRONG NUMBER'); 18


end if;
end;
Enter value for num: 123
old 6: i:=&num;
new 6: i:=123;
PL/SQL procedure successfully completed.

SQL>
Enter value for num: 407
old 6: i:=&num;
new 6: i:=407;
407IS AN ARMSTRONG NUMBER
PL/SQL procedure successfully completed.

PROGRAM FOR MULTIPLICATION TABLE:

SQL> set serveroutput on;


SQL> declare
a number;
b number;
i number;
n number;
s number;
begin
a:=&ulimit;
b:=&llimit; 10
n:=&n;
for i in a..b loop
s:=i*n;

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 81


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

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

PL/SQL procedure successfully completed.

Post-Experiment Questions :

Q.1 Where The Procedures Are Stored In Database?


Q.2 What Is The Difference Between A User Defined Function And A Stored Procedure?
Q.3 How Can We Call Stored Procedures Inside Store Procedures?

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 82


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

EXPERIMENT NO. 7

Aim: Design and implementation of payroll processing systems.

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

2. Establish ODBC connection

3. In the administrator tools open data source ODBC

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

6. ADODC CONTROL FOR SALARY FORM:-

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.

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 83


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

SQL>create table emp(eno number primary key,enamr varchar(20),age number,addr


varchar(20),DOB date,phno number(10));

Table created.

SQL>create table salary(eno number,edesig varchar(10),basic number,da number,hra


number,pf number,mc number,met number,foreign key(eno) references emp);

Table created.

TRIGGER to calculate DA,HRA,PF,MC


SQL> create or replace trigger employ
after insert on salary
declare
cursor cur is select eno,basic from salary;
begin
for cur1 in cur loop
update salary set
hra=basic*0.1,da=basic*0.07,pf=basic*0.05,mc=basic*0.03 where hra=0; 9 end loop;
end;

Trigger created.

PROGRAM FOR FORM 1


Private Sub emp_Click() Form
Show End
Sub Private
Sub exit_Click()
Unload Me
End Sub Private
Sub salary_Click()
Form3.Show
End Sub

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 84


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

PROGRAM FOR FORM 2


Private Sub add_Click()
Adodc1.Recordset.AddNew MsgBox "Record added"
End Sub Private
Sub clear_Click()
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

PROGRAM FOR FORM 3


Private Sub add_Click()
Adodc1.Recordset.AddNew MsgBox "Record added"
End Sub
Private Sub
clear_Click()

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 85


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

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:

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 86


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

RESULT:

Thus payroll system was designed and implemented successfully.

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 87


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

EXPERIMENT NO. 8

Aim : Design and implementation of Library Information systems.

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

2. Establish ODBC connection

3. In the administrator tools open data source ODBC

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

6. ADODC CONTROL FOR library FORM:-

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.

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 88


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

CREATE TABLE Status ( code INTEGER, description CHAR(30), PRIMARY KEY


(code) );
CREATE TABLE Media( media_id INTEGER, code INTEGER, PRIMARY KEY
(media_id),
FOREIGN KEY (code) REFERENCES Status );
CREATE TABLE Book(ISBNCHAR(14), title CHAR(128), author CHAR(64),
year INTEGER, dewey INTEGER, price REAL, PRIMARY KEY (ISBN) );
CREATE TABLE BookMedia( media_id INTEGER, ISBN CHAR(14), PRIMARY
KEY (media_id),
FOREIGN KEY (media_id) REFERENCES Media,
FOREIGN KEY (ISBN) REFERENCES Book);
CREATE TABLE Customer( ID INTEGER, name CHAR(64), addr CHAR(256),
DOB CHAR(10),
phone CHAR(30), username CHAR(16), password CHAR(32), PRIMARY KEY
(ID),
UNIQUE (username) );

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 89


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

CREATE TABLE Card( num INTEGER, fines REAL, ID INTEGER, PRIMARY


KEY (num),
FOREIGN KEY (ID) REFERENCES Customer );
CREATE TABLE Checkout( media_id INTEGER, num INTEGER, since CHAR(10),
until CHAR(10), PRIMARY KEY (media_id),
FOREIGN KEY (media_id) REFERENCES Media,
FOREIGN KEY (num) REFERENCES Card );
CREATE TABLE Location( name CHAR(64), addr CHAR(256), phone CHAR(30),
PRIMARY KEY (name) );
CREATE TABLE Hold( media_id INTEGER, num INTEGER, name CHAR(64),
until CHAR(10),
queue INTEGER, PRIMARY KEY (media_id, num),
FOREIGN KEY (name) REFERENCES Location,
FOREIGN KEY (num) REFERENCES Card,
FOREIGN KEY (media_id) REFERENCES Media );
CREATE TABLE Stored_In( media_id INTEGER, name char(64), PRIMARY KEY
(media_id),
FOREIGN KEY (media_id) REFERENCES Media ON DELETE CASCADE,
FOREIGN KEY (name) REFERENCES Location );
CREATE TABLE Librarian( eid INTEGER, ID INTEGER NOT NULL, Pay REAL,
Loc_name CHAR(64) NOT NULL, PRIMARY KEY (eid),
FOREIGN KEY (ID) REFERENCES Customer ON DELETE CASCADE,
FOREIGN KEY (Loc_name) REFERENCES Location(name) );
CREATE TABLE Video( title CHAR(128), year INTEGER, director CHAR(64),
rating REAL, price REAL, PRIMARY KEY (title, year) );
CREATE TABLE VideoMedia( media_id INTEGER, title CHAR(128), year
INTEGER,
PRIMARY KEY (media_id), FOREIGN KEY (media_id) REFERENCES Media,
FOREIGN KEY (title, year) REFERENCES Video );
INSERT INTO Customer(ID, name, addr, DOB, phone, username, password)
VALUES
(60201, 'Jason L. Gray', '2087 Timberbrook Lane, Gypsum, CO 81637',
'09/09/1958', '970-273-9237', 'jlgray', 'password1');

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 90


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

INSERT INTO Customer(ID, name, addr, DOB, phone, username, password)


VALUES
(89682, 'Mary L. Prieto', '1465 Marion Drive, Tampa, FL 33602',
'11/20/1961', '813-487-4873', 'mlprieto', 'password2');
INSERT INTO Customer(ID, name, addr, DOB, phone, username, password)
VALUES
(64937, 'Roger Hurst', '974 Bingamon Branch Rd, Bensenville, IL 60106',
'08/22/1973', '847-221-4986', 'rhurst', 'password3');
INSERT INTO Customer(ID, name, addr, DOB, phone, username, password)
VALUES
(31430, 'Warren V. Woodson', '3022 Lords Way, Parsons, TN 38363',
'03/07/1945', '731-845-0077', 'wvwoodson', 'password4');
INSERT INTO Customer(ID, name, addr, DOB, phone, username, password)
VALUES
(79916, 'Steven Jensen', '93 Sunny Glen Ln, Garfield Heights, OH 44125',
'12/14/1968', '216-789-6442', 'sjensen', 'password5');
INSERT INTO Customer(ID, name, addr, DOB, phone, username, password)
VALUES
(93265, 'David Bain', '4356 Pooh Bear Lane, Travelers Rest, SC 29690',
'08/10/1947', '864-610-9558', 'dbain', 'password6');
INSERT INTO Customer(ID, name, addr, DOB, phone, username, password)
VALUES
(58359, 'Ruth P. Alber', '3842 Willow Oaks Lane, Lafayette, LA 70507',
'02/18/1976', '337-316-3161', 'rpalber', 'password7');
INSERT INTO Customer(ID, name, addr, DOB, phone, username, password)
VALUES
(88564, 'Sally J. Schilling', '1894 Wines Lane, Houston, TX 77002',
'07/02/1954', '832-366-9035', 'sjschilling', 'password8');
INSERT INTO Customer(ID, name, addr, DOB, phone, username, password)
VALUES
(57054, 'John M. Byler', '279 Raver Croft Drive, La Follette, TN 37766',
'11/27/1954', '423-592-8630', 'jmbyler', 'password9');

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 91


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

INSERT INTO Customer(ID, name, addr, DOB, phone, username, password)


VALUES
(49312, 'Kevin Spruell', '1124 Broadcast Drive, Beltsville, VA 20705',
'03/04/1984', '703-953-1216', 'kspruell', 'password10');
INSERT INTO Card(num, fines, ID) VALUES ( 5767052, 0.0, 60201);
INSERT INTO Card(num, fines, ID) VALUES ( 5532681, 0.0, 60201);
INSERT INTO Card(num, fines, ID) VALUES ( 2197620, 10.0, 89682);
INSERT INTO Card(num, fines, ID) VALUES ( 9780749, 0.0, 64937);
INSERT INTO Card(num, fines, ID) VALUES ( 1521412, 0.0, 31430);
INSERT INTO Card(num, fines, ID) VALUES ( 3920486, 0.0, 79916);
INSERT INTO Card(num, fines, ID) VALUES ( 2323953, 0.0, 93265);
INSERT INTO Card(num, fines, ID) VALUES ( 4387969, 0.0, 58359);
INSERT INTO Card(num, fines, ID) VALUES ( 4444172, 0.0, 88564);
INSERT INTO Card(num, fines, ID) VALUES ( 2645634, 0.0, 57054);
INSERT INTO Card(num, fines, ID) VALUES ( 3688632, 0.0, 49312);
INSERT INTO Location(name, addr, phone) VALUES ('Texas Branch',
'4832 Deercove Drive, Dallas, TX 75208', '214-948-7102');
INSERT INTO Location(name, addr, phone) VALUES ('Illinois Branch',
'2888 Oak Avenue, Des Plaines, IL 60016', '847-953-8130');
INSERT INTO Location(name, addr, phone) VALUES ('Louisiana Branch',
'2063 Washburn Street, Baton Rouge, LA 70802', '225-346-0068'); INSERT
INTO Status(code, description) VALUES (1, 'Available'); INSERT INTO
Status(code, description) VALUES (2, 'In Transit'); INSERT INTO
Status(code, description) VALUES (3, 'Checked Out'); INSERT INTO
Status(code, description) VALUES (4, 'On Hold');
INSERT INTO Media( media_id, code) VALUES (8733, 1);
INSERT INTO Media( media_id, code) VALUES (9982, 1);
INSERT INTO Media( media_id, code) VALUES (3725, 1);
INSERT INTO Media( media_id, code) VALUES (2150, 1);
INSERT INTO Media( media_id, code) VALUES (4188, 1);
INSERT INTO Media( media_id, code) VALUES (5271, 2);
INSERT INTO Media( media_id, code) VALUES (2220, 3);
INSERT INTO Media( media_id, code) VALUES (7757, 1);

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 92


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

INSERT INTO Media( media_id, code) VALUES (4589, 1);


INSERT INTO Media( media_id, code) VALUES (5748, 1);
INSERT INTO Media( media_id, code) VALUES (1734, 1);
INSERT INTO Media( media_id, code) VALUES (5725, 1);
INSERT INTO Media( media_id, code) VALUES (1716, 4);
INSERT INTO Media( media_id, code) VALUES (8388, 1);
INSERT INTO Media( media_id, code) VALUES (8714, 1);
INSERT INTO Book(ISBN, title, author, year, dewey, price) VALUES
('978-0743289412', 'Lisey''s Story', 'Stephen King',
2006, 813, 10.0);
INSERT INTO Book(ISBN, title, author, year, dewey, price) VALUES
('978-1596912366', 'Restless: A Novel', 'William Boyd',
2006, 813, 10.0);
INSERT INTO Book(ISBN, title, author, year, dewey, price) VALUES
('978-0312351588', 'Beachglass', 'Wendy Blackburn',
2006, 813, 10.0);
INSERT INTO Book(ISBN, title, author, year, dewey, price) VALUES
('978-0156031561', 'The Places In Between', 'Rory Stewart',
2006, 910, 10.0);
INSERT INTO Book(ISBN, title, author, year, dewey, price) VALUES
('978-0060583002', 'The Last Season', 'Eric Blehm',
2006, 902, 10.0);
INSERT INTO Book(ISBN, title, author, year, dewey, price) VALUES
('978-0316740401', 'Case Histories: A Novel', 'Kate Atkinson',
2006, 813, 10.0);
INSERT INTO Book(ISBN, title, author, year, dewey, price) VALUES
('978-0316013949', 'Step on a Crack', 'James Patterson, et al.',
2007, 813, 10.0);
INSERT INTO Book(ISBN, title, author, year, dewey, price) VALUES
('978-0374105235', 'Long Way Gone: Memoirs of a Boy Soldier',
'Ishmael Beah', 2007, 916, 10.0);
INSERT INTO Book(ISBN, title, author, year, dewey, price) VALUES
('978-0385340229', 'Sisters', 'Danielle Steel', 2006, 813, 10.0);

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 93


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

INSERT INTO BookMedia(media_id, ISBN) VALUES (8733, '978-0743289412');


INSERT INTO BookMedia(media_id, ISBN) VALUES (9982, '978-1596912366');
INSERT INTO BookMedia(media_id, ISBN) VALUES (3725, '978-1596912366');
INSERT INTO BookMedia(media_id, ISBN) VALUES (2150, '978-0312351588');
INSERT INTO BookMedia(media_id, ISBN) VALUES (4188, '978-0156031561');
INSERT INTO BookMedia(media_id, ISBN) VALUES (5271, '978-0060583002');
INSERT INTO BookMedia(media_id, ISBN) VALUES (2220, '978-0316740401');
INSERT INTO BookMedia(media_id, ISBN) VALUES (7757, '978-0316013949');
INSERT INTO BookMedia(media_id, ISBN) VALUES (4589, '978-0374105235');
INSERT INTO BookMedia(media_id, ISBN) VALUES (5748, '978-0385340229');
INSERT INTO Checkout(media_id, num, since, until) VALUES
(2220, 9780749, '02/15/2007', '03/15/2007');
INSERT INTO Video(title, year, director, rating, price) VALUES
('Terminator 2: Judgment Day', 1991, 'James Cameron', 8.3, 20.0);
INSERT INTO Video(title, year, director, rating, price) VALUES
('Raiders of the Lost Ark', 1981, 'Steven Spielberg', 8.7, 20.0);
INSERT INTO Video(title, year, director, rating, price) VALUES
('Aliens', 1986, 'James Cameron', 8.3, 20.0);
INSERT INTO Video(title, year, director, rating, price) VALUES
('Die Hard', 1988, 'John McTiernan', 8.0, 20.0);
INSERT INTO VideoMedia(media_id, title, year) VALUES
( 1734, 'Terminator 2: Judgment Day', 1991);
INSERT INTO VideoMedia(media_id, title, year) VALUES
( 5725, 'Raiders of the Lost Ark', 1981);
INSERT INTO VideoMedia(media_id, title, year) VALUES
( 1716, 'Aliens', 1986);
INSERT INTO VideoMedia(media_id, title, year) VALUES
( 8388, 'Aliens', 1986);
INSERT INTO VideoMedia(media_id, title, year) VALUES
( 8714, 'Die Hard', 1988);
INSERT INTO Hold(media_id, num, name, until, queue) VALUES
(1716, 4444172, 'Texas Branch', '02/20/2008', 1);

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 94


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

INSERT INTO Librarian(eid, ID, pay, Loc_name) Values


(2591051, 88564, 30000.00, 'Texas Branch');
INSERT INTO Librarian(eid, ID, pay, Loc_name) Values
(6190164, 64937, 30000.00, 'Illinois Branch');
INSERT INTO Librarian(eid, ID, pay, Loc_name) Values
(1810386, 58359, 30000.00, 'Louisiana Branch');
INSERT INTO Stored_In(media_id, name) VALUES(8733, 'Texas Branch');
INSERT INTO Stored_In(media_id, name) VALUES(9982, 'Texas Branch');
INSERT INTO Stored_In(media_id, name) VALUES(1716, 'Texas Branch');
INSERT INTO Stored_In(media_id, name) VALUES(1734, 'Texas Branch');
INSERT INTO Stored_In(media_id, name) VALUES(4589, 'Texas Branch');
INSERT INTO Stored_In(media_id, name) VALUES(4188, 'Illinois Branch');
INSERT INTO Stored_In(media_id, name) VALUES(5271, 'Illinois Branch');
INSERT INTO Stored_In(media_id, name) VALUES(3725, 'Illinois Branch');
INSERT INTO Stored_In(media_id, name) VALUES(8388, 'Illinois Branch');
INSERT INTO Stored_In(media_id, name) VALUES(5748, 'Illinois Branch');
INSERT INTO Stored_In(media_id, name) VALUES(2150, 'Louisiana Branch');
INSERT INTO Stored_In(media_id, name) VALUES(8714, 'Louisiana Branch');
INSERT INTO Stored_In(media_id, name) VALUES(7757, 'Louisiana Branch');
INSERT INTO Stored_In(media_id, name) VALUES(5725, 'Louisiana Branch');

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.password = <user input>;
/* Book search for customers */
SELECT B.ISBN, B.title, B.author, B.year,
(SELECT COUNT(*)
FROM BookMedia BM
WHERE BM.ISBN = B.ISBN AND BM.code = 1) AS num_available
FROM Book B

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 95


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

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

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 96


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

WHERE S.code = M.code AND M.media_id = <user input>;


/* Create a new Hold */
INSERT INTO Hold(media_id, num, name, until, queue) VALUES
(<user input>, <user input>, <user input>, <user input>,
nvl((SELECT MAX(H.queue)
FROM Hold H
WHERE H.media_id = <user input>), 0) + 1 );
/* Cancel Hold, Step 1: Remove the entry from hold */
DELETE FROM Hold
WHERE media_id = <user input> AND num = <user input>
/* Cancel Hold, Step 2: Update queue for this item */
UPDATE Hold
SET queue = queue-1
WHERE media_id = <user input> AND queue > <user input>;
/* Functions needed to view information about a customer */ /*
View the customer's card(s) */
SELECT CR.num, CR.fines
FROM Card CR
WHERE CR.ID = <user input>;
/* View media checked out on a given card */
SELECT B.title, B.author, B.year, BM.media_id, CO.since, CO.until
FROM Checkout CO, BookMedia BM, Book B
WHERE CO.num = <user input> AND CO.media_id = BM.media_id AND B.ISBN =
BM.ISBN
UNION
SELECT V.title, V.director, V.year, VM.media_id, CO.since, CO.until
FROM Checkout CO, VideoMedia VM, Book B
WHERE CO.num = <user input> AND CO.media_id = VM.media_id AND
VM.title = V.title AND VM.year = V.year;
/* View media currently on hold for a given card */
SELECT B.title, B.author, B.year, BM.media_id, H.until, H.queue, SI.name
FROM Hold H, BookMedia BM, Book B, Stored_In SI
WHERE H.num = <user input> AND H.media_id = BM.media_id AND B.ISBN =

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 97


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

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

WHERE H.num = <user input> AND H.media_id = VM.media_id AND


VM.title = V.title AND VM.year = V.year AND SI.media_id = H.media_id;
/* View the total amount of fines the customer has to pay */
SELECT SUM(CR.fines)
FROM Card CR
WHERE CR.ID = <user input>;
/* *\
Functions reserved for librarians
\* */

/* Add new customer */

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 */

INSERT INTO Checkout(media_id, num, since, until) VALUES

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 98


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

(<user input>, <user input>, <user input>, <user input>);


/* Remove the entry for Stored_In */
DELETE FROM Stored_In WHERE
media_id = <user input>;
/* Change the status code of the media */
UPDATE Media
SET code = <user input> WHERE
media_id = <user input>;
/* Remove the entry from Checkout */
DELETE FROM Checkout
WHERE media_id = <user input>;
/* Create the entry in Stored_In */
INSERT INTO Stored_In(media_id, name) VALUES (<user input>, <user input>);
/* Find the next Hold entry for a given media */
SELECT H.num, H.name, H.until
FROM Hold H
WHERE H.queue = 1 AND H.media_id = <user input>;
/* Change the Stored_In entry to the target library branch */
UPDATE Stored_In
SET name = <user input> WHERE
media_id = <user input>;
/* Find the customer that should be notified about book arrival */
SELECT C.name, C.phone, CR.num
FROM Customer C, Card CR, Hold H
WHERE H.queue = 1 AND H.name = <user input> AND H.media_id = <user input> AND
CR.num = H.num AND C.ID = CR.ID;

/* Add a new entry into the Book table */

INSERT INTO Book(ISBN, title, author, year, dewey, price) VALUES


(<user input>, <user input>, <user input>, <user input>, <user input>,
<user input>);

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 99


JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

/* Add a new entry into the Video table */

INSERT INTO Video(title, year, director, rating, price) VALUES


(<user input>, <user input>, <user input>, <user input>, <user input>);
/* Add a new Media object */

INSERT INTO Media( media_id, code) VALUES (<user input>, 1);


/* Add a new BookMedia object */

INSERT INTO BookMedia(media_id, ISBN) VALUES (<user input>, <user input>);


/* Add a new VideoMedia object */

INSERT INTO VideoMedia(media_id, title, year) VALUES


(<user input>, <user input>, <user input>);

/* Remove an entry from the BookMedia table */


DELETE FROM BookMedia
WHERE media_id = <user input>;
/* Remove an entry from the VideoMedia table */
DELETE FROM VideoMedia
WHERE media_id = <user input>;

/* Remove an entry from the Media table */


DELETE FROM Media
WHERE media_id = <user input>;
/* Remove an entry from the Book table */
DELETE FROM Book
WHERE ISBN = <user input>;
/* Remove an entry from the Video table */
DELETE FROM Video

WHERE title = <user input> AND year = <user input>;


/* Update the customer's fines */

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

Aim : Design and implementation of Student Information systems.

Description:

A student information system (SIS), student management system, school administration


software or student administration system is a management information system for
education establishments to manage student data. Student information systems provide
capabilities for registering students in courses; documenting grading, transcripts, results of
student tests and other assessment scores; building student schedules; tracking student
attendance; and managing many other student-related data needs in a school.

Steps:

1. Create a database for library which request the using SQL

2. Establish ODBC connection

3. In the administrator tools open data source ODBC

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

6. ADODC CONTROL FOR library FORM:-

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.

ii. ALL_COURSES Table


This table keeps the courses offered by students in different departments in the school. The
table contains the following columns; COURCE_ID, COURCE_TITLE, and
COURCE_CODE. The COURCE_ID is the primary key column.

iii. APP_USER_A Table


This table contains application login details for application administrators. The table columns
are; USRNAME, PASSWD and ADMIN_ID. The column ADMIN_ID is the primary key
column.

iv. APP_USER_L Table


This table contains application login details for application lecturers. The table columns are;
USRNAME, PASSWD and LECTURER_ID. The column LECTURER_ID is the primary
key column.

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.

vi. DEPARTMENTS Table


This table holds information about the schools departments. The table contains the following
columns;
DEPARTMENT_ID and DEPARTMENT_NAME. The column DEPARTMENT_ID is the
primary key column.

vii. GRADES Table

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.

viii. LECTURERS Table

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.

ix. REG_TABLE Table.

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

Aim : To Study about Automatic Backup of Files and Recovery of Files.

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.

Creating a Backup and Recovery Plan

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.

Figuring Out a Backup Plan

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.

 Do we have the equipment to perform backups? We must have backup hardware to


perform backups. To perform timely backups, we may need several backup devices and
several sets of backup media. Backup hardware includes tape drives, optical drives, and
removable disk drives. Generally, tape drives are less expensive but slower than other
types of drives.

 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.

The Basic Types of Backup

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.

Differential and Incremental Backups

The difference between differential and incremental backups is extremely important. To


understand the distinction between them. As it shows, with differential backups we back up
all the files that have changed since the last full backup (which means that the size of the
differential backup grows over time). With incremental backups, we only back up files that
have changed since the most recent full or incremental backup (which means the size of the
incremental backup is usually much smaller than a full backup).

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.

Selecting Backup Devices and Media

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?

Common Backup Solutions

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."

Buying and Using Tapes

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:

Thus the study of automatic backup of files was performed successfully.

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

Aim : To implement various TCL commands

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.

Pre- Experiment Questions :

Q.1 What is a Transaction?


Q.2 Define ACID properties.
Q.3 How do we overcome failure in a transaction?
Q.4 In what circumstances transaction will roll back?

DATABASE MANAGEMENT SYSTEMS LAB (KCS-551) Manual (CS, V SEM) Page 114
JSS Academy of Technical Education – NOIDA
Department of Computer Science & Engineering

ROLLBACK AND COMMIT:

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.

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
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=&#39;Scott&#39;;
savepoint D2;
selete from emp where ename=&#39;King&#39;;
rollback D2;
commit;

Post-Experiment Questions:

Q.1 Differentiate between complete and partial rollback?


Q.2 What is the advantage of savepoint command?
Q.3 Why do we use commit command?
Q.4 what is the benefit complete rollback?

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

1. Installing oracle/ MYSQL


2. Creating Entity-Relationship Diagram using case tools.
3. Writing SQL statements Using ORACLE /MYSQL:
a) Writing basic SQL SELECT statements.
b) Restricting and sorting data.
c) Displaying data from multiple tables.
d) Aggregating data using group function.
e) Manipulating data.
f) Creating and managing tables.
4. Normalization
5. Creating cursor
6. Creating procedure and functions
7. Creating packages and triggers
8. Design and implementation of payroll processing system
9. Design and implementation of Library Information System
10. Design and implementation of Student Information System
11. Automatic Backup of Files and Recovery of Files
12. Mini project (Design & Development of Data and Application ) for following :
a) Inventory Control System.
b) Material Requirement Processing.
c) Hospital Management System.
d) Railway Reservation System.
e) Personal Information System.
f) Web Based User Identification System.
g) Timetable Management System.
h) Hotel Management System

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

You might also like