0% found this document useful (0 votes)
90 views47 pages

Dbms Lab Manual23-24

This document provides instructions and guidelines for students taking the Database Management Systems (DBMS) Laboratory course at Raj Kumar Goel Institute of Technology. It outlines general instructions that students should follow in the lab, including bringing their lab record, maintaining silence, and properly shutting down computers. It also lists policies for lab assessment, which will evaluate students based on their performance, record keeping, and viva. The document provides context about the course faculty, department, and academic year. It includes visions, missions, and policies of the institute and department. Finally, it lists the program educational objectives and outcomes for the degree.

Uploaded by

qz5jq94yh2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
90 views47 pages

Dbms Lab Manual23-24

This document provides instructions and guidelines for students taking the Database Management Systems (DBMS) Laboratory course at Raj Kumar Goel Institute of Technology. It outlines general instructions that students should follow in the lab, including bringing their lab record, maintaining silence, and properly shutting down computers. It also lists policies for lab assessment, which will evaluate students based on their performance, record keeping, and viva. The document provides context about the course faculty, department, and academic year. It includes visions, missions, and policies of the institute and department. Finally, it lists the program educational objectives and outcomes for the degree.

Uploaded by

qz5jq94yh2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 47

RAJ KUMAR GOEL INSTITUTE OF TECHNOLOGY

Department of Internet of Things

LABORATORY MANUAL

Faculty
: Ms. Priyanka Singh
Name

Course
: DBMS Lab
Name

Year/Sem : 3rd/5th

Email ID : [email protected]

Department : IoT

Course
: KCS551
Code
Academic
: 2023-24
Year

DBMS Lab (KCS-551) Manual (IT, V SEM)


RAJ KUMAR GOEL INSTITUTE OF TECHNOLOGY
Department of Internet of Things

GENERAL INSTRUCTIONS
Do’s
 Switch off mobiles in the lab.
 Bring your lab record with you.
 Always come to the lab in time.
 Maintain silence and be attentive.
 Keep individual records of observations.
 Always turn off the computer properly before leaving the
lab.
 Return all materials issued to you before leaving the lab.
 Read the instruction manual carefully before performing
any experiment.

Don’ts

 Change current settings.


 Overcrowd near the system.
 Make any mark on instruction manual.
 Drag the stool/chair inside the lab.
 Leave the lab till the lab is over.
 Take any material outside the lab with you.

DBMS Lab (KCS-551) Manual (IT, V SEM)


RAJ KUMAR GOEL INSTITUTE OF TECHNOLOGY
Department of Internet of Things
Lab Assessment Rubrics

Every experiment is assessed from 15 marks. 5 Marks each for performance of experiment, record
and viva-voice. The following rubric is used for assessment of each practical:

Excellent Good Satisfactory Marginal Inadequate


Parameters
(5) (4) (3) (2) (1)
The experiment The The The The experiment
is performed in experiment is experiment is experiment is is performed
efficient manner performed performed performed with multiple
and without correctly with minor with some errors and
Performance error. Also without any error and errors and a ample support is
tested with error. error is little support required to
multiple cases. corrected is required to complete the
without help. perform the experiment.
experiment.
Good Fair Explains the Low Low
understanding of understanding relevance of understandin understanding
the relevance of of the project in bits g of the of the relevance
the experiment. relevance of and pieces. relevance of of the
Answers all the Support is the experiment. The
Viva questions experiment. required to experiment. questions are
correctly. Answers all answer all The questions not answered.
questions questions are answered
correctly but correctly. vaguely.
with low
confidence.
The experiment The The The The experiment
is well recorded experiment is experiment is experiment is is not properly
in the file with well recorded recorded in recorded in recorded.
input and in the file with the file with the file but
Record output. File is input and input and without
checked before output. File is output but proper inputs
specified date. not checked not presented and output.
before neatly.
specified date.

DBMS Lab (KCS-551) Manual (IT, V SEM)


RAJ KUMAR GOEL INSTITUTE OF TECHNOLOGY
Department of Internet of Things

DBMS Lab
(KCS551)

LAB FILE
Name of the Student
University Roll No.
Session
Batch
Year / Semester

DBMS Lab (KCS-551) Manual (IT, V SEM)


RAJ KUMAR GOEL INSTITUTE OF TECHNOLOGY
Department of Internet of Things

Vision of the Institute

To continually develop excellent professional capable of


providing sustainable solutions to challenging problems in
their fields and prove responsible global citizens.

Mission of the Institute

We wish to serve the nation by becoming reputed deemed


university for providing value based professional education.

DBMS Lab (KCS-551) Manual (IT, V SEM)


RAJ KUMAR GOEL INSTITUTE OF TECHNOLOGY
Department of Internet of Things

Quality Policy

We are committed to provide high quality education to the


young students in order to enable them to become excellent
professionals in their chosen fields, so that they can
successfully handle professional & industrial needs.
We aim to achieve it by providing necessary educational
environment, infrastructure and resources continually in
compliance to statutory & regulatory requirements for the
satisfaction of all stake holders.

DBMS Lab (KCS-551) Manual (IT, V SEM)


RAJ KUMAR GOEL INSTITUTE OF TECHNOLOGY
Department of Internet of Things

Quality Objectives
TOWARDS STUDENTS
• Steady Growth in Academic Performance
• Equip for Self Learning
• Make Technology Savvy
• Impart Human Values and Skills to Become
Successful andAdorable

TOWARDS EMPLOYERS AND INDUSTRY

• To Become a Preferred Institute for Our Graduates and


Faculty for Employment

TOWARDS SOCIETY

• To Become a Sensitive, Helpful and Loved Environment


• To Create and Improve Environment Friendly, Pollution
Freeand Safe Work Place to Conserve Energy

DBMS Lab (KCS-551) Manual (IT, V SEM)


RAJ KUMAR GOEL INSTITUTE OF TECHNOLOGY
Department of Internet of Things

Vision of the department


To produce employable, self-disciplined, and competent IT
professionals capable of providing sustainable solutions to
problems in the field of information technology.

Mission of the department


M1: To provide quality knowledge in the field of
InformationTechnology.
M2: To make students capable to serve the industry and
society with their innovative ideas and skills.
M3: To make students lead to contribute towards the overall
progress and development over the globe.

DBMS Lab (KCS-551) Manual (IT, V SEM)


RAJ KUMAR GOEL INSTITUTE OF TECHNOLOGY
Department of Internet of Things

Programme Educational Objectives


(PEOs)
The following Program Educational Objectives (PEOs) of the
department have been established through a consultation process among
all the internal and external stakeholders.

PEO 1: The graduates will exhibit the technical competence and


problem- solving abilities required to have a positive effect on
organizations, people, and procedures at the global level.
PEO 2: The graduates will exhibit effective communication, teamwork,
commitment to quality, and professional ethics to pursue a successful
careerin industry, public services, and research & development.
PEO 3: The graduates will exhibit technical and professional leadership
in the field of their business and profession.
PEO 4: The graduates will exhibit the ability to be life-long learners
who adapt to new tools and technologies to respond to the challenges of
a changing environment.

DBMS Lab (KCS-551) Manual (IT, V SEM)


RAJ KUMAR GOEL INSTITUTE OF TECHNOLOGY
Department of Internet of Things

Programme Outcomes (POs)


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

DBMS Lab (KCS-551) Manual (IT, V SEM)


RAJ KUMAR GOEL INSTITUTE OF TECHNOLOGY
Department of Internet of Things

Programme Specific Outcomes (PSOs)

PSO 1
An ability to develop & manage Information
Technology resources of an individual or
organization.

PSO 2
An ability to develop IT solutions related to E-
governance, E-Commerce, E-Education and/ or
Health Care Management.

DBMS Lab (KCS-551) Manual (IT, V SEM)


RAJ KUMAR GOEL INSTITUTE OF TECHNOLOGY
Department of Internet of Things

DBMS LAB
(KCS-551)

COURSE OUTCOMES
At the end of course, the student will be able to
Bloom’s
CO No. Course Outcome Knowledge
Level (KL)

Understand and apply oracle 11 g products for K2,K4


C306.1 creating tables, views, indexes, sequences and other
database objects.
Design and implement a database schema for K3, K5, K6
company data base, banking data base, library
C306.2 information system, payroll processing system,
student information system.

Write and execute simple and complex queries using K4, K5


C306.3
DDL, DML, DCL and TCL
Write and execute PL/SQL blocks, procedure K4, K5
C306.4
functions, packages and triggers, cursors.
Enforce entity integrity, referential integrity, key K3, K4
C306.5
constraints, and domain constraints on database.

DBMS Lab (KCS-551) Manual (IT, V SEM)


RAJ KUMAR GOEL INSTITUTE OF TECHNOLOGY
Department of Internet of Things

DBMS LAB
(KCS-551)

CO-PO MAPPING

PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12

C306.1 2 3 2 1 2 1 2 1 2 2

C306.2 2 3 2 1 2 1 2 1 2 2

C306.3 2 3 2 1 2 1 2 1 2 2

C306.4 2 3 2 1 1 1 2 1 2 2

C306.5 2 3 2 1 1 2 2 1 2 1 2 2

C306 2 3 2 1 1.6 2 2 1 2 1 2 2

CO-PSO MAPPING
PSO1 PSO2

C306.1 3 3

C306.2 3 3

C306.3 3 3

C306.4 3 3

C306.5 3 3

C306 3 3

DBMS Lab (KCS-551) Manual (IT, V SEM)


RAJ KUMAR GOEL INSTITUTE OF TECHNOLOGY
Department of Internet of Things
DBMS Lab
(KCS-551)
APPENDIX: UNIVERSITY (AKTU) SYLLABUS

The following programs may be developed –


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.

DBMS Lab (KCS-551) Manual (IT, V SEM)


RAJ KUMAR GOEL INSTITUTE OF TECHNOLOGY
Department of Internet of Things

DBMS LAB
(KCS-551)
LIST OF PRACTICALS
Expt. Title of experiment Corresponding
No. CO
C 306.1
1. Creating tables and writing Queries in SQL.

2. To implement various DML Operations on table C 306.1

3. To Implement the restrictions/constraints on the table C 306.2


4. To Alter the structure of the table C 306.2

5. To implement the concept of Joins C 306.2

6. To implement the concept of grouping of Data C 306.2

7. To implement the concept of Sub Queries C 306.2

8. To implement the concept of Indexes and views. C 306.2

9. To implement the basics of PL/SQL. C 306.2

10. To implement the concept of Cursor and Trigger C 306.4

Content Beyond Syllabus


1. Write a program to implement REPORTS. C 306.4

2. Write a program to implement FORMS. C 306.5

DBMS Lab (KCS-551) Manual (IT, V SEM)


RAJ KUMAR GOEL INSTITUTE OF TECHNOLOGY
Department of Internet of Things

DBMS LAB
(KCS-551)
INDEX
(TO BEUSED BYTHE STUDENTS IN THEIR RECORDS)

PRACTICAL Faculty
PRACTICAL NO Date of Date of
NO Signature
Name Conduction Submission
No. with Date

1 Creating tables and writing Queries in SQL

2 To implement various DML Operations on


the table

3 To Implement the restrictions/constraints on

the table

4 To Alter the structure of the table

5 To implement the concept of Joins

6 To implement the concept of grouping of

7 To implement the concept of Sub Queries.

8 To implement the concept of Indexes and

9 To implement the basics of PL/SQL

10 To implement the concept of Cursor and

Trigger.

DBMS Lab (KCS-551) Manual (IT, V SEM)


RAJ KUMAR GOEL INSTITUTE OF TECHNOLOGY
Department of Internet of Things

Lab No: 01
PRACTICAL No: - 01
Objective: Creating tables and writing Queries in SQL.

Introduction about SQL-


SQL (Structured Questionry Language) is a nonprocedural language, you specify what you want,
not how to get it. A block structured format of English key words is used in this Questionry
language. It has the following components.

DDL (Data Definition Language)-


The SQL DDL provides command for defining relation schemas, deleting relations and
modifying relation schema.

DML (DATA Manipulation Language)-


It includes commands to insert tuples into, delete tuples from and modify tuples in the database.

View definition-
The SQL DDL includes commands for defining views.
Transaction Control- SQL includes for specifying the beginning and ending of transactions.

Embedded SQL and Dynamic SQL-


Embedded and Dynamic SQL define how SQL statements can be embedded with in general
purpose programming languages, such as C, C++, JAVA, COBOL, Pascal and Fortran.

Integrity-
The SQL DDL includes commands for specifying integrity constraints that the data stored in the
database must specify. Updates that violate integrity constraints are allowed.

Authorization-
The SQL DDL includes commands for specifying access rights to relations and views.

Data Definition Language-

The SQL DDL allows specification of not only a set of relations but also information about each
relation, including-
 Schema for each relation
 The domain of values associated with each attribute.
 The integrity constraints.
 The set of indices to be maintained for each relation.

DBMS Lab (KCS-551) Manual (IT, V SEM)


RAJ KUMAR GOEL INSTITUTE OF TECHNOLOGY
Department of Internet of Things
 The security and authorization information for each relation.
 The physical storage structure of each relation on disk.

Domain types in SQL-

The SQL standard supports a variety of built in domain types, including-


 Char (n)- A fixed length character length string with user specified length .
 Varchar (n)- A variable character length string with user specified maximum length n.
 Int- An integer.
 Small integer- A small integer.
 Numeric (p, d)-A Fixed point number with user defined precision.
 Real, double precision- Floating point and double precision floating point numbers with
machine dependent precision.
 Float (n)- A floating point number, with precision of at least n digits.
 Date- A calendar date containing a (four digit) year, month and day of the month.
 Time- The time of day, in hours, minutes and seconds Eg. Time ’09:30:00’.
 Number- Number is used to store numbers (fixed or floating point).

Pre-Practical Questions:
Q1. Difference b/w dbms and dbms?
Q2. How syntax of table and data type is define in SQL?
Q3. Differentiate b/w DDL & DML commands.

DDL statement for creating a table-

Syntax-
Create table tablename
(columnname datatype(size), columnname datatype(size));

Creating a table from a table-

Syntax-
CREATE TABLE TABLENAME
[(columnname, columnname, ………)]
AS SELECT columnname, columnname……..FROM tablename;

DBMS Lab (KCS-551) Manual (IT, V SEM)


RAJ KUMAR GOEL INSTITUTE OF TECHNOLOGY
Department of Internet of Things

Insertion of data into tables-

Syntax-
INSERT INTO tablename
[(columnname, columnname, ………)]
Values(expression, expression);

Inserting data into a table from another table:

Syntax-
INSERT INTO tablename
SELECT columnname, columnname, …….
FROM tablename;

Insertion of selected data into a table from another table:

Syntax-
INSERT INTO tablename
SELECT columnname, columnname……..
FROM tablename
WHERE columnname= expression;

Retrieving of data from the tables-

Syntax-
SELECT * FROM tablename;

The retrieving of specific columns from a table-

Syntax-
SELECT columnname, columnname, ….
FROM tablename;

Elimination of duplicates from the select statement-

Syntax-
SELECT DISTINCT columnname, columnname
FROM tablename;

Selecting a data set from table data-

Syntax-
SELECT columnname, columnname
FROM tablename

DBMS Lab (KCS-551) Manual (IT, V SEM)


RAJ KUMAR GOEL INSTITUTE OF TECHNOLOGY
Department of Internet of Things
WHERE searchcondition;

Assignment No.1
Q1. Create the following tables:
i) client_master

columnname datatype size


client_no varchar2 6
name varchar2 20
address1 varchar2 30
address2 varchar2 30
city varchar2 15
state varchar2 15
pincode number 6
bal_due number 10,2

ii) Product_master
Columnname datatype size
Product_no varchar2
Description varchar2
Profit_percent number
Unit_measure varchar2
Qty_on_hand number
Reoder_lvlnumber
Sell_price number
Cost_price number

Q2- Insert the following data into their respective tables:

Clientno Name city pincode state bal.due

0001 Ivan Bombay 400054 Maharashtra 15000


0002 Vandana Madras 780001 Tamilnadu 0
0003 Pramada Bombay 400057 Maharashtra 5000
0004 Basu Bombay 400056 Maharashtra 0
0005 Ravi Delhi 100001 2000
0006 Rukmini Bombay 400050 Maharashtra 0

DBMS Lab (KCS-551) Manual (IT, V SEM)


RAJ KUMAR GOEL INSTITUTE OF TECHNOLOGY
Department of Internet of Things

Data for Product Master:


Product No. Desciption Profit % Unit Qty Reorder Sell Cost
Percent measured on hand lvl price price

P00001 1.44floppies 5 piece 100 20 525 500


P03453 Monitors 6 piece 10 3 12000 11200
P06734 Mouse 5 piece 20 5 1050 500
P07865 1.22 floppies 5 piece 100 20 525 500
P07868 Keyboards 2 piece 10 3 3150 3050
P07885 CD Drive 2.5 piece 10 3 5250 5100
P07965 540 HDD 4 piece 10 3 8400 8000
P07975 1.44 Drive 5 piece 10 3 1050 1000
P08865 1.22 Drive 5 piece 2 3 1050 1000

Post-Practical Questions:
Q3:- On the basis of above two tables answer the following Queries:
i) Find out the names of all the clients.
ii) Retrieve the list of names and cities of all the clients.
iii) List the various products available from the product master table.
iv) List all the clients who are located in Bombay.
v) Display the information for client no 0001 and 0002.
vi) Find the products with description as ‘1.44 drive’ and ‘1.22 Drive’.
vii) Find all the products whose sell price is greater then 5000.
viii) Find the list of all clients who stay in in city ‘Bombay’ or city ‘Delhi’ or ‘Madras’.
ix) Find the product whose selling price is greater than 2000 and less than or equal to
5000.
x) List the name, city and state of clients not in the state of ‘Maharashtra’.

DBMS Lab (KCS-551) Manual (IT, V SEM)


RAJ KUMAR GOEL INSTITUTE OF TECHNOLOGY
Department of Internet of Things

Lab No: 02
PRACTICAL No: - 02
Objective:- To implement various DML Operations on table.

Description

DML ( Data Manipulation Language) Data manipulation is

 The retrieval of information stored in the database.


 The insertion of new information into the database.
 The deletion of information from the database.
 The modification of information stored by the appropriate data model. There are basically
two types.
(i) Procedural DML:- require a user to specify what data are needed and how to get
those data.
(ii) Non Procedural DML : require a user to specify what data are needed without
specifying how to get those data.

Updating the content of a table:


In creation situation we may wish to change a value in table without changing all values in the
tuple . For this purpose the update statement can be used.

Update table name


Set columnname = experision, columnname =expression……
Where columnname = expression;

Deletion Operation:-
A delete reQuestionst is expressed in much the same way as Questionry. We can delete whole
tuple ( rows) we can delete values on only particulars attributes.

Deletion of all rows

Syntax:
Delete from tablename :

Deletion of specified number of rows


Syntax:

Delete from table name


Where search condition ;

DBMS Lab (KCS-551) Manual (IT, V SEM)


RAJ KUMAR GOEL INSTITUTE OF TECHNOLOGY
Department of Internet of Things

Computation in expression lists used to select data

+ Addition - Subtraction
* multiplication ** exponentiation
/ Division () Enclosed operation

Renaming columns used with Expression Lists: - The default output column names can be
renamed by the user if required

Syntax:

Select column name result_columnname,


Columnname result_columnname,
From table name;

Logical Operators:
The logical operators that can be used in SQL sentenced are

AND all of must be included


OR any of may be included
NOT none of could be included

Range Searching: Between operation is used for range searching.

Pattern Searching:
The most commonly used operation on string is pattern matching using the operation ‘like’ we
describe patterns by using two special characters.

 Percent (%) ; the % character matches any substring we consider the following examples.
 ‘Perry %’ matches any string beginning with perry
 ‘% idge % matches any string containing’ idge as substring.
 ‘ - - - ‘ matches any string exactly three characters.
 ‘ - - - % matches any string of at least of three characters.

Oracle functions:
Functions are used to manipulate data items and return result. function follow the format of
function _name (argument1, argument2 ..) .An arrangement is user defined variable or constant.
The structure of function is such that it accepts zero or more arguments.
Examples:
Avg return average value of n

DBMS Lab (KCS-551) Manual (IT, V SEM)


RAJ KUMAR GOEL INSTITUTE OF TECHNOLOGY
Department of Internet of Things
Pre-Practical Questions:
Q1. Define different DML commands.
Q2. Explain how to use operators in SQL commands.
Q3.Differentiate b/w DML delete and truncate commands.

Syntax:
Avg ([distinct/all]n)
Min return minimum value of expr.

Syntax:
MIN((distict/all )expr)
Count Returns the no of rows where expr is not null
Syntax:
Count ([distinct/all)expr]
Count (*) Returns the no rows in the table, including duplicates and those with nulls.
Max Return max value of expr

Syntax:

Max ([distinct/all]expr)
Sum Returns sum of values of n

Syntax:
Sum ([distinct/all]n)
Sorting of data in table
Syntax:
Select columnname, columnname
From table
Order by columnname;

DBMS Lab (KCS-551) Manual (IT, V SEM)


RAJ KUMAR GOEL INSTITUTE OF TECHNOLOGY
Department of Internet of Things

Assignment No. # 2
Post-Practical Questions:

Question.1 Using the table client master and product master answer the following Queries.

i. Change the selling price of ‘1.44 floppy drive to Rs.1150.00


ii. Delete the record with client 0001 from the client master table.
iii. Change the city of client_no’0005’ to Bombay.
iv. Change the bal_due of client_no ‘0001, to 1000.
v. Find the products whose selling price is more than 1500 and also find the new selling
price as original selling price *15.
vi. Find out the clients who stay in a city whose second letter is a.
vii. Find out the name of all clients having ‘a’ as the second letter in their names.
viii. List the products in sorted order of their description.
ix. Count the total number of orders
x. Calculate the average price of all the products.
xi. Calculate the minimum price of products.
xii. Determine the maximum and minimum prices . Rename the tittle as ‘max_price’ and
min_price respectively.
xiii. Count the number of products having price greater than or equal to 1500.

DBMS Lab (KCS-551) Manual (IT, V SEM)


RAJ KUMAR GOEL INSTITUTE OF TECHNOLOGY
Department of Internet of Things

Lab No: 03
PRACTICAL No: - 03

Objective:- To Implement the restrictions/constraints on the table.

Description:
Data constraints: Besides the cell name, cell length and cell data type there are other parameters
i.e. other data constrains that can be passed to the DBA at check creation time. The constraints
can either be placed at column level or at the table level.

i. Column Level Constraints: If the constraints are defined along with the column
definition, it is called a column level constraint.
ii. Table Level Constraints: If the data constraint attached to a specify cell in a table
reference the contents of another cell in the table then the user will have to use table level
constraints.

Null Value Concepts:- while creating tables if a row locks a data value for particular
column that value is said to be null . Column of any data types may contain null values
unless the column was defined as not null when the table was created

Syntax:

Create table tablename


(columnname data type (size) not null ……)

Primary Key: primary key is one or more columns is a table used to uniquickly identity
each row in the table. Primary key values must not be null and must be uniQuestion
across the column. A multicolumn primary key is called composite primary key.

Syntax: primary key as a column constraint


Create table tablename
(columnname datatype (size) primary key,….)
Primary key as a table constraint
Create table tablename
(columnname datatype (size), columnname datatype( size)…
Primary key (columnname,columnname));

UniQuestion key concept:-A uniQuestion is similar to a primary key except that the
purpose of a uniQuestion key is to ensure that information in the column for each record

DBMS Lab (KCS-551) Manual (IT, V SEM)


RAJ KUMAR GOEL INSTITUTE OF TECHNOLOGY
Department of Internet of Things
is uniQuestion as with telephone or devices license numbers. A table may have many
uniQuestion keys.

Syntax: UniQuestion as a column constraint.


Create table table name
(columnname datatype (size) uniQuestion);
UniQuestion as table constraint:
Create table tablename
(columnname datatype (size),columnname datatype (size)…uniQuestion
(columnname,columnname));

Default value concept: At the line of cell creation a default value can be assigned to it.
When the user is loading a record with values and leaves this cell empty, the DBA wil
automatically load this cell with the default value specified. The data type of the default
value should match the data type of the column

Syntax:

Create table tablename


(columnname datatype (size) default value,….);

Foreign Key Concept : Foreign key represents relationship between tables. A foreign
key is column whose values are derived from the primary key of the same of some other
table . the existence of foreign key implies that the table with foreign key is related to the
primary key table from which the foreign key is derived .A foreign key must have
corresponding primary key value in the primary key table to have meaning.
Foreign key as a column constraint

Syntax :
Create table table name
(columnname datatype (size) references another table name);

Foreign key as a table constraint:

Syntax :
Create table name
(columnname datatype (size)….
primary key (columnname);
foreign key (columnname)references table name);

Check Integrity Constraints: Use the check constraints when you need to enforce
intergrity rules that can be evaluated based on a logical expression following are a few
examples of appropriate check constraints.
 A check constraints name column of the coient_master so that the name is entered
in upper case.

DBMS Lab (KCS-551) Manual (IT, V SEM)


RAJ KUMAR GOEL INSTITUTE OF TECHNOLOGY
Department of Internet of Things
 A check constraint on the client_no column of the client _master so that
no client_no value starts with ‘c’

Pre-Practical Questions:
Q1. What to you mean by key constraints in dbms?
Q2. Define primary and foreign key.
Q3.How check integrity constraint applies on a column?

Syntax:
Create table tablename
(columnname datatype (size) CONSTRAINT constraintname)
Check (expression));

Question.2 Create the following tables:


i. Sales_master
Columnname Datatype Size Attributes
Salesman_no varchar2 6 Primary key/first letter
must start with ‘s’
Sal_name varchar2 20 Not null
Address varchar2 Not null
City varchar2 20
State varchar2 20
Pincode Number 6
Sal_amt Number 8,2 Not null, cannot be 0
Tgt_to_get Number 6,2 Not null, cannot be 0
Ytd_sales Number 6,2 Not null, cannot be 0
Remarks Varchar2 30

ii. Sales_order
Columnname Datatype Size Attributes
S_order_no varchar2 6 Primary/first letter must be 0
S_order_date Date 6 Primary key reference clientno
of client_master table
Client_no Varchar2 25
Dely_add Varchar2 6
Salesman_no Varchar2 6 Foreign key references
salesman_no of
salesman_master table
Dely_type Char 1 Delivery part(p)/full(f),default f
Billed_yn Char 1
Dely_date Date Can not be lessthan
s_order_date

DBMS Lab (KCS-551) Manual (IT, V SEM)


RAJ KUMAR GOEL INSTITUTE OF TECHNOLOGY
Department of Internet of Things

Order_status Varchar2 10 Values (‘in


process’;’fulfilled’;back
order’;’canceled

I. Sales_order_details
Column Datatype Size Attributes

S_order_no Varchar2 6 Primary key/foreign


key references
s_order_no of
sales_order
Product_no Varchar2 6 Primary key/foreign
key references
product_no of
product_master
Qty_order Number 8
Qty_disp Number 8
Product_rate Number 10,2

Insert the following data into their respective tables using insert statement:
Data for sales_man master table

Salesman_ Salesma Address City Pin Stat Salam Tg Ytd Remark


no n name code e t t_t Sales
o_
get
500001 Kiran A/14 Bomb 40000 Mah 3000 10 50 Good
worli ay 2 0
500002 Manish 65,narim Bomb 40000 Mah 3000 20 100 Good
an ay 1 0
500003 Ravi P-7 Bomb 40003 Mah 3000 20 100 Good
Bandra ay 2 0
500004 Ashish A/5 Juhu Bomb 40004 Mah 3500 20 150 Good
ay 4 0

(ii)
Data for salesorder table:
S_orderno S_orderdate Client no Dely Bill Salesman no Delay Orderstatus
type yn date
019001 12-jan-96 0001 F N 50001 20-jan- Ip
96
019002 25-jan-96 0002 P N 50002 27-jan- C
96

DBMS Lab (KCS-551) Manual (IT, V SEM)


RAJ KUMAR GOEL INSTITUTE OF TECHNOLOGY
Department of Internet of Things

016865 18-feb-96 0003 F Y 500003 20-feb- F


96
019003 03-apr-96 0001 F Y 500001 07-apr- F
96
046866 20-may-96 0004 P N 500002 22- C
may-96
010008 24-may-96 0005 F N 500004 26- Ip
may-96

(iii)
Data for sales_order_details table:

S_order no Product no Qty ordered Qty disp Product_rate


019001 P00001 4 4 525
019001 P07965 2 1 8400
019001 P07885 2 1 5250
019002 P00001 10 0 525
046865 P07868 3 3 3150
046865 P07885 10 10 5250
019003 P00001 4 4 1050
019003 P03453 2 2 1050
046866 P06734 1 1 12000
046866 P07965 1 0 8400
010008 P07975 1 0 1050
010008 P00001 10 5 525

DBMS Lab (KCS-551) Manual (IT, V SEM)


RAJ KUMAR GOEL INSTITUTE OF TECHNOLOGY
Department of Internet of Things

Lab No: 04
PRACTICAL No: - 04

Objective:- To Alter the structure of the table

Description:
Modifying the Structure of Tables- Alter table command is used to changing the structure of a
table. Using the alter table clause you cannot perform the following tasks:

(i) change the name of table


(ii) change the name of column
(iii) drop a column
(iv) decrease the size of a table if table data exists.

The following tasks you can perform through alter table command.

(i) Adding new columns:


Syntax
ALTER TABLE tablename
ADD (newcolumnname newdatatype (size));

(ii) Modifying existing table


Syntax:
ALTER TABLE tablename
MODIFY (newcolumnname newdatatype (size));

NOTE: Oracle not allow constraints defined using the alter table, if the data in the table, violates
such constraints.

Removing/Deleting Tables- Following command is used for removing or deleting a table.

Syntax:
DROP TABLE tabename:

Defining Integrity constraints in the ALTER TABLE command-

You can also define integrity constraints using the constraint clause in the ALTER TABLE
command. The following examples show the definitions of several integrity constraints.

Pre-Practical Questions:
Q1. Differentiate b/w alter and update command.

DBMS Lab (KCS-551) Manual (IT, V SEM)


RAJ KUMAR GOEL INSTITUTE OF TECHNOLOGY
Department of Internet of Things
Q2. Differentiate b/w delete and drop command.
Q3. How to add a key constraint in a table after create it?

(1) Add PRIMARY KEY-


Syntax:
ALTER TABLE tablename
ADD PRIMARY KEY(columnname);

(2) Add FOREIGN KEY-


Syntax:
ALTER TABLE tablename
ADD CONSTRAINT constraintname
FOREIGN KEY(columnname) REFERENCES tablename;
Droping integrity constraints in the ALTER TABLE command:

You can drop an integrity constraint if the rule that if enforces is no longer true or if the
constraint is no longer needed. Drop the constraint using the ALTER TABLE command with the
DROP clause. The following examples illustrate the droping of integrity constraints.

(1) DROP the PRIMARY KEY-


Syntax:
ALTER TABLE tablename
DROP PRIMARY KEY

(2) DROP FOREIGN KEY-


Syntax:
ALTER TABLE tablename
DROP CONSTRAINT constraintname;

Assignment No.4
Question 1. Create the following tables:
Challan_Header
Column name data type size Attributes
Challan_no varchar2 6 Primary key
s_order_no varchar2 6 Foreign key references s_order_no of
sales_order table
challan_date date not null
billed_yn char 1 values (‘Y’,’N’). Default ‘N’

DBMS Lab (KCS-551) Manual (IT, V SEM)


RAJ KUMAR GOEL INSTITUTE OF TECHNOLOGY
Department of Internet of Things

Table Name : Challan_Details


Column name data type size Attributes
Challan_no varchar2 6 Primary key/Foreign key references
Product_no of product_master
Qty_disp number 4,2 not null

Q2. Insert the following values into the challan header and challan_details tables:

(i) Challan No S_order No Challan Date Billed

CH9001 019001 12-DEC-95 Y


CH865 046865 12-NOV-95 Y
CH3965 010008 12-OCT-95 Y

Data for challan_details table

Challan No Product No Qty Disp


CH9001 P00001 4
CH9001 P07965 1
CH9001 P07885 1
CH6865 P07868 3
CH6865 P03453 4
CH6865 P00001 10
CH3965 P00001 5
CH3965 P07975 2

Post-Practical Questions:
Q1. Make the primary key to client_no in client_master.
Q2. Add a new column phone_no in the client_master table.
Q3. Add the not null constraint in the product_master table with the columns description, profit
percent , sell price and cost price.
Q4. Change the size of client_no field in the client_master table.
Q5. Select product_no, description where profit percent is between 20 and 30 both inclusive.

DBMS Lab (KCS-551) Manual (IT, V SEM)


RAJ KUMAR GOEL INSTITUTE OF TECHNOLOGY
Department of Internet of Things

Lab No: 05
PRACTICAL No: - 05
Objective:- To implement the concept of Joins

Description

Joint Multiple Table (Equi Join): Some times we require to treat more than one table as though
manipulate data from all the tables as though the tables were not separate object but one single
entity. To achieve this we have to join tables.Tables are joined on column that have dame data
type and data with in tables.

The tables that have to be joined are specified in the FROM clause and the joining
attributes in the WHERE clause.

Algorithm for JOIN in SQL:


1. Cartesian product of tables (specified in the FROM clause)
2. Selection of rows that match (predicate in the WHERE clause)
3. Project column specified in the SELECT clause.

Pre-Practical Questions:
Q1. Why joins are required in database?
Q2. What is minimal requirement for two tables to apply join command?
Q3. Differentiate b/w inner and outer join.

1. Cartesian product:-
Consider two table student and course
Select B.*,P.*
FROM student B, course P;

2. INNER JOIN:
Cartesian product followed by selection
Select B.*,P.*
FROM student B, Course P
WHERE B.course # P.course # ;

3. LEFT OUTER JOIN:

DBMS Lab (KCS-551) Manual (IT, V SEM)


RAJ KUMAR GOEL INSTITUTE OF TECHNOLOGY
Department of Internet of Things
LEFT OUTER JOIN = Cartesian product + selection but include rows from the left
table which are unmatched pat nulls in the values of attributes belonging to th e second
table
Exam:
Select B.*,P*
FROM student B left join course p
ON B.course # P.course #;

4. RIGHT OUTER JOIN:


RIGHT OUTER JOIN = Cartesian product + selection but include rows from right table
which are unmatched

Exam:
Select B.*,P.*
From student B RIGHT JOIN course P
B.course# = P course # ;

5. FULL OUTER JOIN


Exam
Select B.*,P.*
From student B FULL JOIN course P
On B.course # = P course # ;

ASSIGNMENT NO. 5
Post-Practical Questions:
1. Find out the product which has been sold to ‘Ivan Sayross.’
2. Find out the product and their quantities that will have do delivered.
3. Find the product_no and description of moving products.
4. Find out the names of clients who have purchased ‘CD DRIVE’
5. List the product_no and s_order_no of customers haaving qty ordered less than 5 from
the order details table for the product “1.44 floppies”.
6. Find the products and their quantities for the orders placed by ‘Vandan Saitwal ’ and
“Ivan Bayross”.
7. Find the products and their quantities for the orders placed by client_no “ C00001” and
“C00002”
8. Find the order No,, Client No and salesman No. where a client has been received by more
than one salesman.
9. Display the s_order_date in the format “dd-mm-yy” e.g. “12- feb-96”
10. Find the date , 15 days after date.

DBMS Lab (KCS-551) Manual (IT, V SEM)


RAJ KUMAR GOEL INSTITUTE OF TECHNOLOGY
Department of Internet of Things

Lab No: 06
PRACTICAL No: - 06

Objective:- To implement the concept of grouping of Data.

Description
Grouping Data From Tables:
There are circumstances where we would like to apply the aggregate function not only to a
single set of tuples, but also to a group of sets of tuples, we specify this wish in SQL using the
group by clause. The attribute or attributes given in the group by clause are used to form group.
Tuples with the same value on all attributes in the group by clause are placed in one group.

Pre-Practical Questions:
Q1. Why groups are required in database?
Q2. What is minimal requirement for two tables to group together?
Q3. Differentiate b/w group & join syntax.

Syntax:
SELECT columnname, columnname
FROM tablename
GROUP BY columnname;
At times it is useful to state a condition that applies to groups rather than to tuples. For example
we might be interested in only those branches where the average account balance is more than
1200. This condition does not apply to a single tuple, rather it applies to each group constructed
by the GROUP BY clause. To express such Questionry, we use the having clause of SQL. SQL
applies predicates in the having may be used.
Syntax:
SELECT columnname, columnname
FROM tablename
GROUP BY columnname;
HAVING searchcondition;

DBMS Lab (KCS-551) Manual (IT, V SEM)


RAJ KUMAR GOEL INSTITUTE OF TECHNOLOGY
Department of Internet of Things
Assignment No.6
Post-Practical Questions:

Q1.- Print the description and total quantity sold for each product.
Q2.- Find the value of each product sold.
Q3.- Calculate the average quantity sold for each client that has a maximum order value of
15000.
Q4.- Find out the products which has been sold to Ivan.
Q5.- Find the names of clients who have ‘CD Drive’.
Q6.- Find the products and their quantities for the orders placed by ‘Vandana’ and ‘Ivan’.
Q7.- Select product_no, total qty_ordered for each product.
Q8.- Select product_no, product description and qty ordered for each product.
Q9.- Display the order number and day on which clients placed their order.
Q10.- Display the month and Date when the order must be delivered.

DBMS Lab (KCS-551) Manual (IT, V SEM)


RAJ KUMAR GOEL INSTITUTE OF TECHNOLOGY
Department of Internet of Things

Lab No: 07
PRACTICAL No: - 07

Objective:- To implement the concept of Sub Queries.

Description
Sub Queries:- A Sub Queries is a form of an SQL statement that appears inside another SQL
statement. It also termed as nested Questionry. The statement containing a Sub Queries called a
parent statement. The rows returned bu the Sub Queries are use by the following statement.
It can be used by the following commands:
1. To insert records in the target table.
2. To create tables and insert records in this table.
3. To update records in the target table.
4. To create view.
5. To provide values for the condition in the WHERE , HAVING IN , SELECT,UPDATE,
and DELETE statements.

Example:Creating clientmaster table from oldclient_master, table

Create table client_master


AS SELECT * FROM oldclient_master;

Pre-Practical Questions:
Q1. How logical operators apply at SQL table?
Q2. How sub quires apply at table?
Q3.Difference b/w quires and sub-quires.

Using the Union, Intersect and Minus Clause:


Union Clause:
The user can put together multiple Queries and combine their output using the union clause . The
union clause merges the output of two or more Queries into a single set of rows and column.
The final output of union clause will be

Output: = Records only in Questionry one + records only in Questionry two + A single set of
records with is common in the both Queries.

Syntax:

DBMS Lab (KCS-551) Manual (IT, V SEM)


RAJ KUMAR GOEL INSTITUTE OF TECHNOLOGY
Department of Internet of Things
SELECT columnname, columname FROM tablename 1
UNION
SELECT columnname, columnname From tablename2;

Intersect Clause: The use can put together multiple Queries and their output using the interest
clause. The final output of the interest clause will be :

Output =A single set of records which are common in both Queries

Syntax:
SELECT columnname, columnname
FROM tablename 1
INTERSECT
SELECT columnname, columnname
FROM tablename 2;

MINUS CLAUSE:- The user can put together multiple Queries and combine their output =
records only in Questionry one
Syntax:
SELECT columnname, columnname
FROM tablename ;
MINUS
SELECT columnname, columnname
FROM tablename ;

Assignment NO.7
Post-Practical Questions:
1. Find the product_no and description of non- moving products.
2. Find the customer name, address, city and pincode for the client who has placed order no
“019001”
3. Find the client names who have placed order before the month of may 96.
4. Find out if product “1.44 Drive” is ordered by only client and print the client_no name to
whom it was sold.
5. find the names of client who have placed orders worth Rs.10000 or more.
6. Select the orders placed by ‘Rahul Desai”
7. Select the names of persons who are in Mr. Pradeep’s department and who have also
worked on an inventory control system.
8. Select all the clients and the salesman in the city of Bombay.
9. Select salesman name in “Bombay” who has atleast one client located at “Bombay”
10. Select the product_no, description, qty_on-hand,cost_price of non_moving items in the
product_master table.

DBMS Lab (KCS-551) Manual (IT, V SEM)


RAJ KUMAR GOEL INSTITUTE OF TECHNOLOGY
Department of Internet of Things

Lab No: 08

PRACTICAL No: - 08

Objective:- To implement the concept of Indexes and views.

Description:
Indexes- An index is an ordered list of content of a column or group of columns in a table. An index
created on the single column of the table is called simple index. When multiple table columns are
included in the index it is called composite index.
Creating an Index for a table:-
Syntax (Simple)
CREATE INDEX index_name
ON tablename(column name);
Composite Index:-
CREATE INDEX index_name
ON tablename(columnname,columnname);
Creating an UniQuestion Index:-
CREATE UNIQUESTION INDEX indexfilename
ON tablename(columnname);
Dropping Indexes:-
An index can be dropped by using DROP INDEX
SYNTAX:-
DROP INDEX indexfilename;
Views:-
Logical data is how we want to see the current data in our database. Physical data is how
this data is actually placed in our database.
Views are masks placed upon tables. This allows the programmer to develop a method
via which we can display predetermined data to users according to our desire.
Views may be created fore the following reasons:

1. The DBA stores the views as a definition only. Hence there is no duplication of data.
2. Simplifies Queries.
3. Can be Questionried as a base table itself.
4. Provides data security.
5. Avoids data redundancy.

DBMS Lab (KCS-551) Manual (IT, V SEM)


RAJ KUMAR GOEL INSTITUTE OF TECHNOLOGY
Department of Internet of Things
Creation of Views:-
Syntax:-
CREATE VIEW viewname AS
SELECT columnname,columnname
FROM tablename

WHERE columnname=expression_list;

Renaming the columns of a view:-


Syntax:-
CREATE VIEW viewname AS
SELECT newcolumnname….
FROM tablename
WHERE columnname=expression_list;

Selecting a data set from a view-


Syntax:-
SELECT columnname, columnname
FROM viewname
WHERE search condition;

Destroying a view-
Syntax:-
DROP VIEW viewname;

Assignment # 8
Post-Practical Questions:

Q1. Create an index on the table client_master, field client_no.


Q2. Create an index on the sales_order, field s_order_no.
Q3. Create an composite index on the sales_order_details table for the columns s_order_no
and product_no.
Q4. Create an composite index ch_index on challan_header table for the columns challan no
and s_order_no.
Q5. Create an uniQuestion index on the table salesman_master, field salesman_no.
Q6. Drop index ch_index on table challan_header.
Q7. Create view on salesman_master whose sal_amt is less than 3500.
Q8. Create a view client_view on client_master and rename the columns as name, add1, add2,
city, pcode, state respectively.

DBMS Lab (KCS-551) Manual (IT, V SEM)


RAJ KUMAR GOEL INSTITUTE OF TECHNOLOGY
Department of Internet of Things

Lab No: 09
PRACTICAL No: - 09

Objective:- To implement the basics of PL/SQL.

Introduction – PL/SQL bridges the gap between database technology and procedural
programming languages. It can be thought of as a development tool that extends the facilities of
Oracles SQL database language. Via PL/SQL you can insert, delete, update and retrieve table
data as well as use procedural techniQuestions such as writing loops or branching to another
block of code.

PL/SQL Block structure-

DECLARE
Declarations of memory variables used later
BEGIN
SQL executable statements for manipulating table data.
EXCEPTIONS
SQL and/or PL.SQL code to handle errors.
END;

Displaying user Messages on the screen – Any programming tool requires a method through
which messages can be displayed to the user.

dbms_output is a package that includes a number of procedure and functions that accumulate
information in a buffer so that it can be retrieved later. These functions can also be used to
display message to the user.
put_line: put a piece of information in the buffer followed by a end of line marker. It can also be
used to display message to the user.
Setting the server output on:

SET SERVER OUTPUT ON:

Example: Write the following code in the PL/SQL block to display message to user
DBMS_OUTPUT.PUT_LINE(‘Display user message’)

DBMS Lab (KCS-551) Manual (IT, V SEM)


RAJ KUMAR GOEL INSTITUTE OF TECHNOLOGY
Department of Internet of Things

Conditional control in PL/SQL-


Syntax:
IF <condition> THEN
<Action>
ELSEIF<condition>
<Action>
ELSE
<Action>
ENDIF;
The WHILE LOOP:
Syntax:
WHILE <condition>
LOOP
<Action>
END LOOP;

The FOR LOOP statement:


Syntax:
FOR variable IN [REVERSE] start—end
LOOP
<Action>
END LOOP;

The GOTO statement: The goto statement allows you to change the flow of control within a
PL/SQL Block.
Assignment No.9
Q1. WAP in PL/SQL for addition of two numbers.

Q2. WAP in PL/SQL for addition of 1 to 100 numbers.

Q3. WAP in PL/SQL to check the given number is even or odd.

Q4. WAP in PL/SQL to inverse a number, eg. Number 5639 when inverted must be display
output 9365.

Q5. WAP in PL/SQL for changing the price of product ‘P00001’ to 4000 if the price is less than
4000 in product_master table. The change is recorded in the old_price_table along with
product_no and the date on which the price was changed last.

DBMS Lab (KCS-551) Manual (IT, V SEM)


RAJ KUMAR GOEL INSTITUTE OF TECHNOLOGY
Department of Internet of Things

Lab No: 10
PRACTICAL No: 10

Objective:- To implement the concept of Cursor and Trigger.

Description:
Cursor– We have seen how oracle executes an SQL statement. Oracle DBA uses a work area for
its internal processing. This work area is private to SQL’s operation and is called a cursor.
The data that is stored in the cursor is called the Active Data set. The size of the cursor in
memory is the size required to hold the number of rows in the Active Data Set.

Explicit Cursor- You can explicitly declare a cursor to process the rows individually. A cursor
declared by the user is called Explicit Cursor. For Queries that return more than one row, You
must declare a cursor explicitly.
The data that is stored in the cursor is called the Active Data set. The size of the cursor in
memory is the size required to hold the number of rows in the Active

Why use an Explicit Cursor- Cursor can be used when the user wants to process data one row
at a time.

Explicit Cursor Management- The steps involved in declaring a cursor and manipulating data
in the active data set are:-
 Declare a cursor that specifies the SQL select statement that you want to process.
 Open the Cursor.
 Fetch the data from the cursor one row at a time.
 Close the cursor.

Explicit Cursor Attributes- Oracle provides certain attributes/ cursor variables to control the
execution of the cursor. Whenever any cursor(explicit or implicit) is opened and used Oracle
creates a set of four system variables via which Oracle keeps track of the ‘Current’ status of the
cursor. You
 Declare a cursor that specifies the SQL select statement that you want to process.
 Open the Cursor.
 Fetch the data from the cursor one row at a time.
 Close the cursor.
How to Declare the Cursor:-

The General Syntex to create any perticular cursor is as follows:-


Cursor <Cursorname> is Sql Statement;

DBMS Lab (KCS-551) Manual (IT, V SEM)


RAJ KUMAR GOEL INSTITUTE OF TECHNOLOGY
Department of Internet of Things

How to Open the Cursor:-

The General Syntex to Open any perticular cursor is as follows:-


Open Cursorname;

Fetching a record From the Cursor:-


The fetch statement retrieves the rows from the active set to the variables one at a time. Each
time a fetch is executed. The focus of the DBA cursor advances to the next row in the Active set.
One can make use of any loop structute(Loop-End Loop along with While,For) to fetch the
records from the cursor into variable one row at a time.

The General Syntex to Fetch the records from the cursor is as follows:-
Fetch cursorname into variable1,variable2,______

Closing a Cursor:-

The General Syntex to Close the cursor is as follows:-


Close <cursorname>;

Database Triggers:-
Database triggers are procedures that are stored in the database and are implicitly executed(fired)
when the contents of a table are changed.

Use of Database Triggers:-


Database triggers support Oracle to provide a highly customized database management system.
Some of the uses to which the database triggers can be put to customize management
information in Oracle are as follows:-
 A Trigger can permit DML statements against a table anly if they are issued, during
regular bussiness hours or on predetermined weekdays.
 A trigger can also be used to keep an audit trail of a table along with the operation
performed and the time on which the operation was performed.
 It can be used to prevent invalid transactions.
 Enforce complex security authorizations.

How to apply DataBase Triggers:-


A trigger has three basic parts:-
1. A triggering event or statement.
2. A triger restriction
3. A trigger action.

Types of Triggers:-

DBMS Lab (KCS-551) Manual (IT, V SEM)


RAJ KUMAR GOEL INSTITUTE OF TECHNOLOGY
Department of Internet of Things

Using the various options , four types of triggers can be created:-


1. Before Statement Trigger:- Before executing the triggering statement, the trigger action
is executed.
2. Before Row Trigger:- Before modifying the each row affected by the triggering
statement and before appropriate integrity constraints, the trigger is executed if the trigger
restriction either evaluated to TRUE or was not included.’
3. After Ststement Trigger:- After executing the triggering statement and applying any
deferred integrity canstraints, the trigger action is executed.
4. After row Trigger:- After modifying each row affected by the triggering statement and
possibly applying appropriate integrity constraints, the trigger action is executed for the
current row if the trigger restriction either evaluates to TRUE or was not included.

Syntex For Creating Trigger:-


The syntex for Creating the Trigger is as follows:-

Create or replace Trigger<Triggername> {Before,After} {Delete, Insert, Update } On


<Tablename> For Each row when Condition
Declare
<Variable declarations>;
<Constant Declarations>;
Begin
<PL/SQL> Subprogram Body;
Exception
Exception Pl/SQL block;
End;

How to Delete a Trigger:-

The syntex for Deleting the Trigger is as follows:-


Drop Trigger <Triggername>;

Assignmnet No.10
Q1:- Two Tables are there

Table Name:0- Employee

Column Name Data Type Size Attributes


Emp_Code Varchar2 10 Primary Key
Ename Varchar2 20 The name of the Candidate
Deptno Number 5 The Department No
Job Vrachar2 20 The Employee Job Detail
Salary Number 8,2 The Current salary of Em

Table name:- Emp_raise

DBMS Lab (KCS-551) Manual (IT, V SEM)


RAJ KUMAR GOEL INSTITUTE OF TECHNOLOGY
Department of Internet of Things

Column Name Data Type Size Attributes


Emp_Code Varchar2 10 Primary Key
Raise_Date date The Date On which the raise was given
Raise_Amt Number 8,2 The raise given to the employee

The HRD manager has decided to raise the salary for all the employees in the Dept No 20 by 5%.
Whenever any such raise is given to the employees, a record for the same is maintained in the
emp_raise table. It includes the EmpNo, the date when the raise was given and the actual raise.
Write a PL/SQL block to update the salary of each employee and insert a record in the emp_raise
table.

Q2:- Two Tables are there

Table Name:- Client_Master

Column Name Data Type Size Attributes


Client No Varchar2 6 Primary Key/First letter must start with ‘C’
Name Varchar2 20 Not Null
City Varchar2 10
State Vrachar2 10
Bal_Due Number 10,2

Table name:- auditclient

Column Name Data Type Size Attributes


Client_No Varchar2 10 Primary Key
Name Varchar2 20
Bal_Due Number 10,2
Operation Varchar2 8
Odate Date

Create a transparent audit system for a table Client master. The system must keep track of the
records that are being deleted or modified and when they have been deleted or modified.

DBMS Lab (KCS-551) Manual (IT, V SEM)

You might also like