Lab Manual Bcse2014 Dbms
Lab Manual Bcse2014 Dbms
B.TECH
DATABASE MANAGEMENT SYSTEM LAB
COURSE CODE:-BCSE2014
Room no. :
1
______________________
DIVISION :
DIVISION CHAIR
LAB TECH
2
VISION AND MISSION OF GU
GU’s Vision
"To be known globally for education, research, and innovation at the intersection of disciplines"
GU’s Mission
TO PLACE ALL STAKEHOLDERS in pursuit of perfection, discovery and innovation in
one’s own discipline, while being aware that all one does, emerges from and integrates into a
wider common human good.
TO DEVELOP a learning orientation across the entire university ecosystem that goes beyond
domain knowledge so as to ensure that learning and problem-solving continue for life.
TO ENABLE the finest student and faculty bodies to learn together, through the most evolved
education processes in an atmosphere of rigour and discipline, which emerges from and
integrates with real life industry, science and commerce processes; so as to develop an expert
body that understands all aspects of societal challenges; and works with teams to tackle
complex problems that directly benefit society.
3
VISION AND MISSION OF SCHOOL
VISION OF SCSE
To be known globally a premier school for value-based education, multidisciplinary research and
innovation
MISSION OF SCSE
M2: Establish state-of-the-art facilities for Analysis, Design and Implementation to develop
sustainable ethical solutions
M4: Involve the students in group activity including that of professional bodies to develop leadership
and communication skills
4
Code
Course
Program Outcome→
Course Name
Engineering Knowledge
PO1
Problem analysis
PO2
Design/development of solutions
PO3
Conduct investigations of complex problems
PO4
Modern tool usage
PO5
The engineer and society
PO6
PROGRAMME OUTCOMES
PSO1
To introduce upcoming domains like artificial intelligence, Robotics,
Augmented reality, Data analytics, Ubiquitous Computing to develop insights
for problem solving.
PSO2
5
COURSE OUTCOMES
Mapping CO-PO
CO/PO Mapping
(S/M/W indicates strength of correlation) S-Strong, M-Medium, L-Low
COs Programme Outcomes(POs)
PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12 PSO1 PSO2
CO1 S M M M S M M L L S S
CO2 S M M S M M L S S
CO3 S L S L L M S
CO4 S S M M
CO5 S L L S L M
CO6 S L L S L L
6
EVALUATION SCHEME
Mode of Evaluation: Continuous assessment of the progress will be done week followed by an
External Exam Practical (EEP) Laboratory Exam. This evaluation scheme is without PBL.
Midterm lab
--- 20
examination
Lab experiment R1 20
Total: 100
7
ASSESSMENT PROCESS
Maximum Marks: 20
Level of Achievement
Assessment Excellent (4) Very Good Fair (2) Poor (1) Mapped
Parameter (3) PO
8
Rubric R1: ETE Lab Test
Maximum Marks: 20
Level of Achievement
Assessment Excellent (4) Very Good Fair (2) Poor (1) Mapped
Parameter (3) PO
9
and no over- but some significant interpreted
interpretation conclusions errors, data.
may be omissions
suspect or still present
over-
interpreted
Maximum Marks: 20
Level of Achievement
10
Graphs incomplete
(wherever
applicable
are labeled
and show
trends
Session…………………………
Class………………………... Subject Code……………………
Experiment Name……………………………
11
No Knowledge of Result Analysis
. Tools and and Data
Procedures Interpretation
(10) (10)
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
Session………………………… Class………………………...
Subject Code……………………
Experiment Name……………………………
12
S Univ. Name of student Dat Assessment Total
Roll No. e Parameter (20)
No
. Knowledge of Result Analysis
Tools and and Data
Procedures Interpretation
(10) (10)
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
Session………………………… Class………………………...
Subject Code……………………
Experiment Name……………………………
13
S Univ. Name of Dat Assessment Total
Roll No. student e Parameter (20)
No
. Result Organization
Representation of Report and
and Discussion Timely
(10) Submission
(10)
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
3……………………………………
Session…………………. Class…………………………..
Subject Code……………………….
14
Rubric R1: Rubric for Assessing Lab Report
Maximum Marks: 20
Total Marks: 40
R1 R2(20
(40) )
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
2,……………………….…………….3,……………………………………..……
15
LIST OF EXPERIMENTS
5. Implement SINGLE ROW functions (Character, Numeric, Date functions) and GROUP functions
(avg, count, max, min, sum).
6. Implement various type of SET OPERATORS (Union, Intersect, Minus) and JOINS.
8. Implement the concept of Data Control Language (DCL), Transaction Control Language (TCL).
10. Write a PL/SQL block to satisfy some conditions by accepting input from the user.
11. Write a PL/SQL block for greatest of three numbers using IF AND ELSEIF
12. Write a PL/SQL block for summation of odd numbers using for LOOP
17. Create a Database for Customer Sale/purchase and implement various queries on it.
16
EXPERIMENT DETAILS
Experiment 1
Title Data Definition Language
Objective Study of Data Definition language commands. - Create table, Alter Table,Drop Table, Rename
Table.
Algorithm The SQL DDL allows specification of not only a set of relations but also information about each
relation, including-
/Theory
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.
The security and authorization information for each relation.
ALTER TABLE
DROP TABLE
17
RENAME TABLE
TRUNCATE
Post Lab
Assignment
(If Any)
Experiment 2
Title Data Manipulation Language Statements.
Pre- Knowledge of
requisite
ORACLE Queries
Algorithm Data Manipulation Language (DML) statements are used for managing data in
database. DML commands are not auto-committed. It means changes made
/Theory
by DML command are not permanent to database, it can be rolled back.
DML statements are used for managing data within schema objects. Some examples:
o DELETE - deletes all records from a table, the space for the records remain
Syntax INSERT INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...);
Post Lab
Assignment
(If Any)
Experiment 3
Title SELECT Command
18
Objective Study of SELECT command with different clauses.
Pre- Knowledge of
requisite
ORACLE
Algorithm
SQL SELECT Statement
/Theory
The most commonly used SQL command is SELECT statement. SQL SELECT
statement is used to query or retrieve data from a table in the database. A query may
retrieve information from specified columns or from all of the columns in the table.
To create a simple SQL SELECT Statement, you must specify the column(s) name
and the table name. The whole query is called SQL SELECT Statement.
Syntax
Syntax of SQL SELECT Statement:
Post Lab
Assignment
(If Any)
Experiment 4
Title Keys
Pre- Knowledge of
requisite
ORACLE COMMANDS
Algorithm
SQL Constraints
/Theory
SQL constraints are used to specify rules for the data in a table.
If there is any violation between the constraint and the data action, the action is aborted by the
19
constraint.
Constraints can be specified when the table is created (inside the CREATE TABLE statement) or
after the table is created (inside the ALTER TABLE statement).
PRIMARY KEY - A combination of a NOT NULL and UNIQUE. Ensures that a column (or
combination of two or more columns) have a unique identity which helps to find a
particular record in a table more easily and quickly
FOREIGN KEY - Ensure the referential integrity of the data in one table to match values
in another table
The PRIMARY KEY constraint uniquely identifies each record in a database table.
Most tables should have a primary key, and each table can have only ONE primary key.
Post Lab
Assignment
(If Any)
Experiment 5
Title SINGLE ROW functions and Group functions
Objective Study of SINGLE ROW functions (Character, Numeric, Date functions) and GROUP functions (avg,
21
count, max, min, sum).
Pre- Knowledge of
requisite
ORACLE
Algorithm
Oracle SQL supplies a rich library of in-built functions which can be employed for
/Theory various tasks. The essential capabilities of functions can be the case conversion of
strings, in-string or substring operations, mathematical computations on numeric
data, and date operations on date type values. SQL Functions optionally take
arguments from the user and mandatorily return a value.
Aggregate functions perform a variety of actions such as counting all the rows in a table,
averaging a column's data, and summing numeric data.
Aggregates can also search a table to find the highest "MAX" or lowest "MIN" values in a
column. As with other types of queries, you can restrict, or filter out the rows these functions
act on with the WHERE clause. For example, if a manager needs to know how many employees
work in an organization, the aggregate function named COUNT(*) can be used to produce this
information.The COUNT(*) function shown in the below SELECT statement counts all rows in a
table.
Syntax The SELECT query below demonstrates the use of NVL function.
22
AVG( [ALL | DISTINCT] expression )
COUNT(*)
MAX(expression)
MIN(expression)
Post Lab
Assignment
(If Any)
Experiment 6(a)
Title SET Operators.
Post Lab
Assignment
(If Any)
Experiment 6(b)
23
Title Joins
Pre- Knowledge of
requisite
ORACLE COMMANDS
Algorithm SQL JOIN
/Theory An SQL JOIN clause is used to combine rows from two or more tables, based on a common field
between them.
The most common type of join is: SQL INNER JOIN (simple join). An SQL INNER
JOIN return all rows from multiple tables where the join condition is me.
SQL INNER JOIN Keyword
The INNER JOIN keyword selects all rows from both tables as long as there is a match between
the columns in both table
The LEFT JOIN keyword returns all rows from the left table (table1), with the matching
rows in the right table (table2). The result is NULL in the right side when there is no
match.
The RIGHT JOIN keyword returns all rows from the right table (table2), with the
matching rows in the left table (table1). The result is NULL in the left side when there is
no match.
The FULL OUTER JOIN keyword returns all rows from the left table (table1) and from
the right table (table2).
The FULL OUTER JOIN keyword combines the result of both LEFT and RIGHT joins.
Syntax
SQL INNER JOIN Syntax
24
SELECT column_name(s)
FROM table1
INNER JOIN table2
ON table1.column_name=table2.column_name;
Post Lab
Assignment
(If Any)
Experiment 7
Title Subqueries
25
statement. The rows returned bu the subquery are use by the following statement.
/Theory
Syntax
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 query one + records only in query two + A single set of records with is
common in the both queries.
Syntax:
FROM tablename 1
UNION
26
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 :
Syntax:
FROM tablename 1
INTERSECT
FROM tablename 2;
MINUS CLAUSE:- The user can put together multiple queries and combine their output =
records only in query one
Syntax:
FROM tablename ;
MINUS
FROM tablename ;
Post Lab
Assignment
(If Any)
Experiment 8
Title Control languages
27
Objective Study and implement the concept of Data Control Language (DCL), Transaction Control
Language (TCL).
Pre- Knowledge of
requisite
ORACAL COMMANDS
Algorithm
TCL command
/Theory
Transaction Control Language(TCL) commands are used to manage transactions in
database.These are used to manage the changes made by DML statements. It also allows
statements to be grouped together into logical transactions.
Commit command
Rollback command
This command restores the database to last commited state. It is also use with savepoint
command to jump to a savepoint in a transaction.
savepoint command is used to temporarily save a transaction so that you can rollback to that
point whenever necessary.
Syntax commit;
rollback to savepoint-name;
savepoint savepoint-name;
Post Lab
Assignment
(If Any)
28
Experiment 9
Title Views
A view contains rows and columns, just like a real table. The fields in a view are fields from one
or more real tables in the database.
You can add SQL functions, WHERE, and JOIN statements to a view and present the data as if
the data were coming from one single table.
Note: A view always shows up-to-date data! The database engine recreates the data, using the
view's SQL statement, every time a user queries a view.
Syntax
SQL CREATE VIEW Syntax
CREATE VIEW view_name AS
SELECT column_name(s)
FROM table_name
WHERE condition
Syntax:-
SELECT newcolumnname….
FROM tablename
WHERE columnname=expression_list;
29
Selecting a data set from a view-
Syntax:-
FROM viewname
Destroying a view-
Syntax:-
Post Lab
Assignment
(If Any)
Experiment 10
Title PL/SQL Program for Addition of Two numbers
Objective PL/SQL Control Structure provides conditional tests, loops, flow control and branches that
let to produce well-structured programs.
Experiment 11
Title PL/SQL block for greatest of three numbers using IF AND ELSEIF
31
10 dbms_output.put_line('A is maximum');
11 else if(b>a)and(b>c)then
12 dbms_output.put_line('B is maximum');
13 else
14 dbms_output.put_line('C is maximum');
15 end if;
16 end;
17 / INPUT Enter value for a: 21
old 7: a:=&a;
new 7: a:=21;
Enter value for b: 12
old 8: b:=&b;
new 8: b:=12;
Enter value for b: 45
old 9: c:=&b;
new 9: c:=45;
OUTPUT C is maximum PL/SQL procedure successfully completed.
Post Lab
Assignment
(If Any)
Experiment 12
Title PL/SQL block for summation of odd numbers using for LOOP
Objective PL/SQL Control Structure provides conditional tests, loops, flow control
Experiment 13
Title PL/SQL Procedure for GCD Numbers
Algorithm Create or replace procedure <procedure_name> (argument {in, out, in out} data type)
{is, as} Variable declaration
/Theory Begin
Pl/SQL Subprogram body.
Exception
Exception PL/SQL Block.
End;
Syntax create or replace procedure pro is
a number(3);
b number(3);
c number(3);
d number(3);
begin a:=&a;
b:=&b;
if(a>b) then c:=mod(a,b);
if(c=0) then
dbms_output.put_line('GCD is');
dbms_output.put_line(b);
else
dbms_output.put_line('GCD is');
dbms_output.put_line(c);
33
end if;
else d:=mod(b,a);
if(d=0) then
dbms_output.put_line('GCD is');
dbms_output.put_line(a);
else
dbms_output.put_line('GCD is');
dbms_output.put_line(d);
end if;
end if;
end;
/
Enter value for a: 8
old 8: a:=&a;
new 8: a:=8;
Enter value for b: 16
old 9: b:=&b;
new 9: b:=16;
Procedure created.
SQL> set serveroutput on;
SQL> execute pro;
GCD is 8
PL/SQL procedure successfully completed
Post Lab
Assignment
(If Any)
Experiment 14
Title PL/SQL Procedure for cursor implementation.
34
SQL>set server output on
declare
ave number(5,2);
tot number(3);
cursor c_mark is select * from st13 where mark1>=40 and mark2>=40 and mark3>=40 and
mark4>=40 and mark5>=40;
begin
dbms_output.put_line('regno name mark1 mark2 mark3 mark4 mark5 total average');
dbms_output.put_line('------------------------------------------------------');
for student in c_mark
loop
tot:=st13.mark1+st13.mark2+st13.mark3+st13.mark4+st13.mark5;
ave:=tot/5; dbms_output.put_line(st13.regno||rpad(st13.name,15)||rpad(st13.mark1,6)||
rpad(st13.mark2,6)||rpad(st13.mark3,6)||rpad(st13.mark4,6)||rpad(st13.mark5,6)||
rpad(tot,8)||rpad(ave,5)); end loop;
end;
/
Post Lab
Assignment
(If Any)
Experiment 15
Title FUNCTION TO FIND FACTORIAL
35
4 f number:=1;
5 begin
6 for i in 1..N loop
7 f:=f*i;
8 end loop;
9 return f;
10 end;
11 /
Function created.
SQL> select fact(2) from dual;
FACT(2)
---------
2
Post Lab
Assignment
(If Any)
36