Dbms
Dbms
LAB MANUAL
Prepared By
M.Lakshmi Shree
1
SCHOOL OF COMPUTING
BONAFIDECERTIFICATE
2024 - 2025_
REGISTER NUMBER:
9 9 1 9 0 0 8 0 2 1
2
EXPERIMENT EVALUATION SUMMARY
3
TABLE OF CONTENTS
No
4
DEPARTMENT OF INFORMATION TECHNOLOGY
ODD SEMESTER 2024-2025
PRE-REQUISITE:
COURSE DESCRIPTION:
The major objective of this lab is to provide a strong foundation in database concepts, technology and
practice to the participants to groom them into database application developers.
COURSE OBJECTIVES:
PEO1: The Graduates will be technically competent to excel in IT industry and to pursue higher studies.
PEO2: The Graduates will possess the skills to design and develop economically and technically feasible computing
systems using modern tools and techniques.
PEO3: The Graduates will have effective communication skills, team spirit, ethical principles and the desire for self
learning to succeed in their professional career.
5
PROGRAMME OUTCOMES (POS)
PO1: Ability to apply knowledge of mathematics, science and computer engineering to solve computational problems.
PO2: Ability to identify, formulates, analyze and derive conclusions in complex computing problems.
PO3: Capability to design and develop computing systems to meet the requirement of industry and society with due
consideration for public health, safety and environment.
PO4: Ability to apply the knowledge of design of experiment and data analysis to derive solutions in complex
computing problems.
PO5: Ability to develop and apply modeling, simulation and prediction tools and techniques to engineering problems.
PO6: Ability to assess and understand the professional, legal, security and societal responsibilities relevant to computer
engineering practice.
PO7: Ability to understand the impact of computing solutions in economic, environmental and societal context for
sustainable development.
PO8: Applying ethical principles and commitment to ethics of IT and software profession.
PO10: Ability to communicate effectively with technical community and with society.
PO11: Demonstrating and applying the knowledge of computer engineering and management principles in software
project development and in multidisciplinary areas.
PO12: Understanding the need for technological changes and engage in life-long learning.
PSO1: Problem-Solving Skills: The ability to apply mathematics, science and computer engineering knowledge to
analyze, design and develop cost effective computing solutions for complex problems with environmental considerations.
PSO2: Professional Skills: The ability to apply modern tools and strategies in software project development using modern
programming environments to deliver a quality product for business accomplishment.
PSO3: Communication and Team Skill: The ability to exhibit proficiency in oral and written communication as individual
or as part of a team to work effectively with professional behaviors and ethics.
PSO 4 : Successful Career and Entrepreneurship : The ability to create a inventive career path by applying innovative
project management techniques to become a successful software professional, an entrepreneur or zest for higher studies
6
COURSE OUTCOMES:
CO1: Design and build a database schema for a given problem domain.
CO2: Populate and query a database using SQL DML/DDL commands.
CO3: Programming PL/SQL including stored procedure, stored functions,
and cursors.
CO and PO Mapping
P P P P P P P P P PO PO PO PSO PSO PSO PSO
O O O O O O O O O 10 11 12 1 2 3 4
1 2 3 4 5 6 7 8 9
CO1 S M M S
CO2 S S S S S S S M L
CO3 S S S L
S- Strong Correlation M- Medium Correlation L – Low Correlation
Assessment Method:
7
Excellent( 15-12) Good( 12-9) Average(9-5)
Poor(5-0)
3. Running project with working explanation
Results and
Excellent( 20-15) Good( 15-10) Average(10-5) 20
Discussion
Poor(5-0)
4. Group members cooperation and documentation
Team work and
Excellent( 10-8) Good( 8-5) Average(5-2) 10
documentation
Poor(2-0)
5. PPT presentation and viva voce
Communication Skill Excellent( 10-8) Good( 8-5) Average(5-2) 10
Poor(2-0)
VIVA VOCE
S.N Database
Experiments Query Output
o schema Techn Commu
ical nication
8
Working with DML and DCL
2 25 25 20 20 10
commands
Working with Built-in functions of
3 25 25 20 20 10
SQL
Programs using PL/SQL and
4 25 25 20 20 10
Cursors
7 Embedded SQL 25 25 20 20 10
INTRODUCTION
A data base management system is a collection of programs that enables users to create and maintain
a database. DBMS is a general purpose software system that facilitates the process of defining,
constructing, manipulating databases for various applications.
Functions of DBMS
Performance monitoring.
9
Ex. No: 1 DATA DEFINITION LANGUAGE (DDL)
Date :
AIM:
OBJECTIVE:
After completing the exercise the students can able to Understand how to create a table with list of fields, Modify
a row using where clause, Drop a table, Delete the unwanted rows in a table.
ALGORITHM:
Step 2: Go to SQL.
Step 5: Type the commands for creating tables and perform various operations on the
tables.
10
DDL COMMAND:
CREATE
ALTER
DROP
TRUNCATE
RENAME
CREATION OF TABLE
QUERY: 01
Q1: Write a query to create a table employee with empno, ename, designation, and salary.
Command:
SQL>CREATE TABLE EMP (EMPNO NUMBER (4), ENAME VARCHAR2 (10), DESIGNATIN
VARCHAR2 (10),SALARY NUMBER (8, 2));
Table created.
Constraints are condition for the data item to be stored into a database.
There are two types of Constraints viz., Column Constraints and Table Constraints.
Syntax
REFERENCES table
11
TABLE DESCRIPTION
It is used to view the table structure to confirm whether the table was created correctly.
QUERY: 02
Q2: Write a query to display the column name and data type of the table employee.
Syntax: This is used to view the structure of the table. SQL: DESC <TABLE NAME>;
Command:
Name Type
--------------- ----------------
EMPNO NUMBER(4)
ENAME VARCHAR2(1)
DESIGNATION VARCHAR2(1)
SALARY NUMBER(8,2)
QUERY: 03
Q3: Write a query for create a from an existing table with all the fields
Syntax: syntax for create a table from an existing table with all fields.
SQL> CREATE TABLE <TRAGET TABLE NAME> SELECT * FROM<SOURCE TABLE NAME>;
Command:
Command:
12
SQL> DESC EMP1
QUERY: 04
Q4: Write a query for create a from an existing table with selected fields
Syntax: Syntax for create a from an existing table with selected fields.
SQL> CREATE TABLE <TRAGET TABLE NAME> AS SELECT EMPNO, ENAMEFROM <SOURCE
TABLE NAME>;
Command:
Command:
QUERY: 05
Q5: Write a query for create a new table from an existing table without any record:
13
Syntax: The syntax for create a new table from an existing table without any record.
SQL> CREATE TABLE <TRAGET TABLE NAME> AS SELECT * FROM<SOURCE TABLE NAME>
WHERE <FALSE CONDITION>;
Command:
To modify structure of an already existing table to add one more columns and also modify
the existing columns.
QUERY: 06
Q6: Write a Query to Alter the column EMPNO NUMBER (4) TO EMPNO NUMBER (6).
Command:
14
SQL> DESC EMP;
QUERY: 07
Q7. Write a Query to Alter the table employee with multiple columns (EMPNO,ENAME.)
Command:
15
Command:
ENAME VARCHAR2(12)
DESIGNATIN VARCHAR2(10)
SALARY NUMBER(8,2);
QUERY: 08
Command:
VARCHAR2(10)
SALARY
NUMBER(8,2) QUALIFICATION
VARCHAR2(6)
16
QUERY: 09
Q9: Write a query to add multiple columns in to employee Syntax: Syntax for add a new column.
REMOVE / DROP
It will delete the table structure provided the table should be empty.
QUERY: 10
17
Command:
SQL> ALTER TABLE EMP DROP COLUMN
ENAME VARCHAR2(12)
DESIGNATIN VARCHAR2(10)
SALARY NUMBER(8,2)
QUALIFICATION VARCHAR2(6)
DOB DATE
QUERY: 11
Command:
18
SQL> ALTER TABLE EMP DROP (DOB,
QUALIFICATION); Table altered.
RENAME
QUERY: 12
Q12. Write a query to rename table emp to employee
Command:
SQL> ALTER TABLE RENAME EMP TO
EMPLOYEE; SQL> DESC EMPLOYEE;
TRUNCATE TABLE
If there is no further use of records stored in a table and the structure has to be retained then the
records alone can be deleted.
Syntax:
Example:
DROP
19
To remove a table along with its structure and data.
Command:
EVALUATION
RESULT:
Thus the SQL commands for DDL commands in DBMS has been verified and executed successfully.
20
Ex. No: 2 DATA MANIPILATION LANGUAGE (DML)
Date :
AIM:
To execute and verify the DML commands are the most frequently used SQL commands and
is used to query and manipulate the existing database objects.
SELECT
INSERT
DELETE
UPDATE
ALGORITHM:
STEP 6: use save point if any changes occur in any portion of the record to undo its original state.
INSERT
The SQL INSERT INTO Statement is used to add new rows of data to a table in the database.
QUERY: 01
Command:
SQL>INSERT INTO EMP VALUES (101,'NAGARAJAN','LECTURER',15000);
1 row created.
QUERY: 02
Q2. Write a query to insert the records in to employee using substitution method.
SQL :> INSERT INTO <TABLE NAME> VALUES< ‘&column name’, ‘&column name 2’, …..);
Command:
SQL> INSERT INTO EMP
VALUES(&EMPNO,'&ENAME','&DESIGNATIN','&SALARY'); Enter value for empno: 102
Enter value for ename:
SARAVANAN
Enter value for designatin:
LECTURER
1 row created.
SQL> /
Enter value for empno: 104
22
Enter value for ename: CHINNI
SELECT
SELECT Statement is used to fetch the data from a database table which returns data in the
form of result table. These result tables are called result-sets.
QUERY: 03
UPDATE
The SQL UPDATE Query is used to modify the existing records in a table. You can use
WHERE clause with UPDATE query to update selected rows, otherwise all the rows would be
affected.
QUERY: 04
Syntax: syntax for update records from the table.SQL> UPDATE <<TABLE NAME> SET
<COLUMNANE>=<VALUE> WHERE <COLUMN NAME=<VALUE>;
Command:
24
EMPNO ENAME DESIGNATIN SALARY
---------- ------------ ------------------- ---------------
101 NAGARAJAN LECTURER 16000
102 SARAVANAN LECTURER 15000
103 PANNERSELVAM ASST. PROF 20000
104 CHINNI HOD,PROF 45000
Update Multiple
Columns:
QUERY: 05
Q5. Write a query to update multiple records from employee.
Command:
1 row updated.
DELETE
25
The SQL DELETE Query is used to delete the existing records from a table. You can use
WHERE clause with DELETE query to delete selected rows, otherwise all the records would be
deleted.
QUERY: 06
Command:
SQL> DELETE EMP WHERE EMPNO=103;
1 row deleted.
26
EVALUATION
RESULT:
Thus the SQL commands for DML has been verified and executed successfully.
27
Ex. No: 3 TCL COMMANDS
Date :
AIM:
To create the SAVE POINT for the transaction and verify the various operations of TCL
commands.
OBJECTIVE:
The SAVEPOINT statement names and marks the current point in the processing of a transaction. With
the ROLLBACK TO statement, savepoints undo parts of a transaction instead of the whole transaction.
An implicit savepoint is marked before executing an INSERT, UPDATE, or DELETE statement. If the
statement fails, a rollback to the implicit savepoint is done. Normally, just the failed SQL statement is
rolled back, not the whole transaction; if the statement raises an unhandled exception, the host
environment
ALGORITHM:
STEP 4: Insert record values into the table or perform any kind of DML operation.
STEP 5: Create the SAVE POINTs for some set of statement on the transaction of database object.
STEP 6: Use the COMMIT command to save the effect of the previous command operation except
DDL command
STEP 7: Use the ROLLBACK TO SP_LABLE / ROLLBACK command for restore the
database status up to the save point
Syntax:
SAVEPOINT<SAVEPOINT_NAME>;
Ex:
SQL> create table ORDER_PROCESSING( Order_ID number(3), Product_ID varchar2(10), Quantity
number(3,2), Price number(4,2));
28
Table created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
1 row created.
SQL> SAVEPOINT C;
Savepoint created.
29
SQL> SELECT * FROM ORDER_PROCESSING;
9 rows selected.
SQL> ROLLBACK TO B;
Rollback complete.
SQL> ROLLBACK TO A;
Rollback complete.
30
SQL> SELECT * FROM ORDER_PROCESSING;
SQL> ROLLBACK;
Rollback complete.
SQL> SELECT * FROM ORDER_PROCESSING;
ORDER_ID PRODUCT_ID QUANTITY PRICE
--------------- -------------------- ----------------
-------------
101 RICE-22 6.5 30.5
102 OIL 2 90.5
SQL> ROLLBACK;
Rollback complete.
SQL> SELECT * FROM ORDER_PROCESSING;
ORDER_ID PRODUCT_ID QUANTITY PRICE
---------------- ------------------- ---------------- -----------
101 RICE-22 6.5 30.5
102 OIL 2 90.5
31
EVALUATION
RESULT:
Thus the SQL commands for creation and various operations on transaction (TCL
COMMAND) save point has been verified and executed successfully.
32
33
Ex. No: 4 WORKING WITH BUILT-IN FUNCTION IN SQL
Date :
Aim
ALGORITHM
Built-in functions are predefined functions that perform a specific task. Built-in functions based
on the values that they take to perform a task, can be classified into two types. They are
Scalar functions
Number functions
Character functions
Date functions
Conversion functions
Other functions
Number functions
ABS(n)
FLOOR(n)
CEIL(n)
EXP(n)
LN(n)
LOG(n)
MOD(n)
POWER(m,n)
ROUND(n[,m])
34
SIGN(n)
SQRT(n)
TRUNC(n[,m])
Character Functions
a. returning number values
ASCII(char)
INSTR(char1,char2[,n[,m]])
INSTRB(char1,char2[,n[,m]])
LENGTH(char)
LENGTHB(char)
CHR(n)
CONCAT(char1,char2)
INITCAP(char)
LPAD(char1,n[,char2])
LTRIM(char[,set])
REPLACE(char,search-string[,replacement-string])
RPAD(char1,n[,char2])
RTRIM(char[,set])
SOUNDEX(char)
SUBSTR(char,m[,n])
SUBSTRB(char,m[,n])
TRANSLATE(char,from,to)
35
UPPER(char)
LOWER(char)
c. Date functions
ADD_MONTHS(d,n)
Last_day(d)
MONTHS_BETWEEN(d1,d2)
NEXT_DAY(d,char)
ROUND(d[,fmt])
TRUNC(d[,fmt])
Element Meaning
MM Month(01-12 ; Jan=01)
DD Day of month(1-31)
D Day of week(1-7)
MI Minute(0-59)
SS Second(0-59)
36
Conversion Functions
TO_CHAR(d[,fmt])
TO_CHAR(n[,fmt])
TO_DATE(char[,fmt])
TO_NUMBER(char[,fmt[,'nlsparams']])
Other functions
greatest(expr[,expr])
least(expr[,expr])
Nvl(expr1,expr2)
UID(user)
Sysdate
Aggregate functions
AVG()
MAX()
MIN()
COUNT()
SUM()
LIST OF EXERCISES
String Functions
37
3. Change all ‘Block A’ in Deplocation column as ‘Block F’
Numeric Functions
10. Find the employee with maximum salary, minimum salary in each department in the
ascending order of depno.
13. Display the rounded value of the ‘salary’ column in ‘Employee’ table.
Date Functions
15.Display the system date in the format mentioned below “27th October 1996”.
17.Display the date two months after the date-of-join for all the employees.
18.Display the last date of the month in the date-of-join for all the employees.
19.Display the months between the current date and the date-of-join.
38
39
40
41
42
EVALUATION
RESULT:
Thus the SQL commands for built in function has been verified and executed successfully
43
Ex. No: 5 SIMPLE PL / SQL PROGRAM
Date :
AIM:
To write a PL/SQL block using different control (if, if else, for loop, while loop,…) statements.
OBJECTIVE:
PL/SQL Control Structure provides conditional tests, loops, flow control and branches that
let to produce well-structured programs
PL/SQL
PL/SQL is Oracle’s procedural language extension to SQL. PL/SQL allows you to mix SQL
PL/SQL.
3. We can have user defined error massages by using concept of exception handling.
PL/SQL Block:
DECLARE
Declaration of variable
Declaration of cursor----------
44
(OPTIONAL) Declaration of exception
BEGIN
EXCEPTION
END;
Declare:
This section is used to declare local variables, cursors, Exceptions and etc. This section is optional.
Executable Section:
This section contains lines of code which is used to complete table. It is mandatory.
Exception Section:
This section contains lines of code which will be executed only when exception is raised.
This section is optional.
Begin
--------
END;
SERVEROUTPUT
This will be used to display the output of the PL/SQL programs. By default this will be off.
Syntax:
Ex:
45
SQL>set serveroutput on
PL/SQL has a variety of control structures that allow you to control the behaviour of the block
as it runs. These structures include conditional statements and loops.
If-then else Case
Labeled case
Searched
While loop
For loop
Syntax:
If <condition1> then
Sequence of statements;
……
Else
Sequence of statements;
End if;
CASE
46
Syntax:
Case test-variable
End case;
Location is NEW YORK
CASE WITHOUT
ELSE
Syntax:
Case test-variable
……
End case;
LABELED CASE
Syntax:
<<label>>
Case test-variable
sequence of statements;
47
……
SEARCHED
CASE Syntax:
Case
……
Location is NEW YORK
When <condition-n> then sequence of statements;
End case;
SIMPLE LOOP
Syntax:
Loop
Sequence of statements;
Exit when
Sequence of statements;
End loop;
End loop;
Goto label;
Where label is a label defined in the PL/SQL block. Labels are enclosed in double angle
brackets. When a goto statement is evaluated, control immediately passes to the statement
PL/SQL PROGRAMS
1: Write PL/SQL block which will calculate some of two numbers and display the output?
DECLARE
A number(2);
B number(2);
C number(3);
BEGIN
A := 10;
B := 20;
C := A + B; DBMS_OUTPUT.PUT_LINE(C);
END;
49
Output:
30
2: Write a PL/SQL block which accepts employee number and increment is salary by 1000?
DECLARE
A number(4); A := &Empno;
Location is NEW YORK
END;
/
50
3: Write a PL/SQL block which empno and delete that row from the emp table?
DECLARE
A number(4);
BEGIN
A := &Empno;
Delete from emp where Empno = A;
END;
/
Algorithm:
Program:
declare
b varchar2(10) := '&b';
c varchar2(10);
l number(2);
i number(2);
g number(2); dvarchar2(10);
51
begin
l:=length(b);
g:=l;
for i in 1..l loop
g,1);
g := g - 1;
d := d ||
c;
end loop;
End;
c:=substr(b);
Location is NEW YORK
OUTPUT:
new 2: b varchar2(10) :=
6. A:=B&B:=A
Program:
declare
end if;
a := 0;
b := 1;
dbms_output.put_line('fibonacci series is');
dbms_output.put_line(a);
dbms_output.put_line(b);
c := a + b;
dbms_output.put_line(c);
a := b;
b :=c;
end loop;
exception
when negative then
dbms_output.put_line('n should be greater than 1');
end
53
;
SQL>
0
1
Algorithm:
Step 9: if both the values are same, then display “The given number is Armstrong”
54
Step 10: Otherwise display “it is not Armstrong” and terminate the loop.
declare
n number:=1634;
s number:=0;
r number;
len number;
m number;
begin
m := n;
len := length(to_char(n));
while n>0
loop
r := mod(n , 10);
s := s + power(r , len);
n := trunc(n / 10);
end loop;
if m = s
then
dbms_output.put_line('Amstrong Number');
else
dbms_output.put_line('Not an Amstrong
Number');
end if;
55
end;
Enter value
of n 153
Output:
number is Armstrong
DECLARE
i NUMBER(3);
j NUMBER(3);
BEGIN
dbms_output.Put_line('The prime numbers are:');
dbms_output.new_line;
i := 2;
LOOP
j := 2;
LOOP
EXIT WHEN( ( MOD(i, j) = 0 )
OR ( j = i ) );
j := j + 1;
END LOOP;
IF( j = i )THEN
56
dbms_output.Put(i||' ');
END IF;
i := i + 1;
exit WHEN i = 100;
END LOOP;
dbms_output.new_line;
END;
OUTPUT:
1
2 3 5 5 7 11
EVALUATION
RESULT:
57
Thus the PL/SQL program has been verified and executed successfully
58