Lab Course File: Course Code:-Bcse2014 Room No.
Lab Course File: Course Code:-Bcse2014 Room No.
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
PROGRAMME OUTCOMES
To
introduce
Co
upcoming
De nd Pr
En domains
sig uct oje
Th vir like
n/ inv Ind ct
En e on To artificial
de est M ivi ma Lif
gin Pro en me Co train intelligence
vel iga od du na e-
eer ble gin nt m studen , Robotics,
op tio ern Et al ge lon
ing m eer an mu ts in Augmented
Program Outcome→ me ns too hic or me g
Kn ana an d nic trendi reality,
nt of l s tea nt Le
ow lysi d sus ati ng Data
of co usa m an arn
led s soc tai on techno analytics,
sol mp ge wo d ing
ge iet na logies. Ubiquitous
uti lex rk fin
y bili Computing
on pro an
ty to develop
s ble ce
insights for
ms
problem
solving.
P P P
Course Course P P P P P P P P P
O O O PSO1 PSO2
Code Name O O O O O O O O O
1 1 1
1 2 3 4 5 6 7 8 9
0 1 2
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)
PO PO PO PO PO PO PO PO PO PO1 PO1 PO1 PSO PSO
1 2 3 4 5 6 7 8 9 0 1 2 1 2
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
Maximum Marks: 20
Level of Achievement
Session…………………………
Class………………………... Subject Code……………………
Experiment Name……………………………
1.
11
2.
3.
4.
5.
6.
7.
8.
9.
10.
Session………………………… Class………………………...
Subject Code……………………
Experiment Name……………………………
1.
12
2.
3.
4.
5.
6.
7.
8.
9.
10.
Session………………………… Class………………………...
Subject Code……………………
Experiment Name……………………………
13
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
3……………………………………
Session…………………. Class…………………………..
Subject Code……………………….
Total Marks: 40
14
R1 R2(20
(40) )
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
2,……………………….…………….3,……………………………………..……
15
LIST OF EXPERIMENTS
Implement SINGLE ROW functions (Character, Numeric, Date functions) and GROUP functions
(avg, count, max, min, sum).
Implement various type of SET OPERATORS (Union, Intersect, Minus) and JOINS.
Implement the concept of Data Control Language (DCL), Transaction Control Language (TCL).
Write a PL/SQL block to satisfy some conditions by accepting input from the user.
Write a PL/SQL block for greatest of three numbers using IF AND ELSEIF
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
Objectiv Study of Data Definition language commands. - Create table, Alter
e Table,Drop Table, Rename Table.
Pre- Knowledge of Basic Database
requisite
Algorith The SQL DDL allows specification of not only a set of relations but also
m information about each relation, including-
ALTER TABLE
ALTER TABLE table_name
ADD column_name datatype;
ALTER TABLE table_name
MODIFY column_name datatype;
ALTER TABLE table_name
DROP COLUMN column_name;
ALTER TABLE table_name
RENAME COLUMN OLDcolumn_name TO NEWcolumn_name;
DROP TABLE
DROP TABLE table_name;
RENAME TABLE
17
TRUNCATE
TRUNCATE TABLE table_name;
Post Lab
Assignm
ent (If
Any)
Experiment 2
Title Data Manipulation Language Statements.
Objectiv Study of Data Manipulation Statements.
e
Pre- Knowledge of
requisite
● ORACLE Queries
Algorith Data Manipulation Language (DML) statements are used for
m managing data in database. DML commands are not auto-committed.
It means changes made by DML command are not permanent to
/Theory
database, it can be rolled back.
DML statements are used for managing data within schema objects. Some
examples:
18
Pre- Knowledge of
requisite
● ORACLE
Algorith
m SQL SELECT Statement
The most commonly used SQL command is SELECT statement. SQL SELECT
/Theory
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:
SELECT column_list FROM table-name
[WHERE Clause]
[GROUP BY clause]
[HAVING clause]
[ORDER BY clause];
Post Lab
Assignm
ent (If
Any)
Experiment 4
Title Keys
Objectiv Study of various type of Integrity Constraints.
e
Pre- Knowledge of
requisite
● ORACLE COMMANDS
Algorith
m 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 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).
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.
Syntax
SQL CREATE TABLE + CONSTRAINT Syntax
CREATE TABLE table_name
(
column_name1 data_type(size) constraint_name,
column_name2 data_type(size) constraint_name,
column_name3 data_type(size) constraint_name,
....
);
20
P_Id int NOT NULL,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Address varchar(255),
City varchar(255),
PRIMARY KEY (P_Id)
)
Post Lab
Assignm
ent (If
Any)
Experiment 5
Title SINGLE ROW functions and Group functions
Objectiv Study of SINGLE ROW functions (Character, Numeric, Date functions) and
e GROUP functions (avg, count, max, min, sum).
Pre- Knowledge of
requisite
● ORACLE
Algorith Oracle SQL supplies a rich library of in-built functions which can be
m employed for various tasks. The essential capabilities of functions
can be the case conversion of strings, in-string or substring
/Theory
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
21
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.
COUNT(*)
MAX(expression)
MIN(expression)
Post Lab
Assignm
22
ent (If
Any)
Experiment 6(a)
Title SET Operators.
Objectiv Study of various type of SET OPERATORS (Union, Intersect, Minus).
e
Pre- Knowledge of
requisite
● Concept of SET Operators.
Algorith Set Operation in SQL
m
SQL supports few Set operations to be performed on table data. These are
used to get meaningful results from data, under different special conditions.
/Theory
Post Lab
Assignm
ent (If
Any)
Experiment 6(b)
Title Joins
Objectiv Study of Various type of JOINS.
e
Pre- Knowledge of
requisite
● ORACLE COMMANDS
Algorith SQL JOIN
m
An SQL JOIN clause is used to combine rows from two or more tables, based
/Theory 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
23
SQL LEFT JOIN Keyword
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
SELECT column_name(s)
FROM table1
INNER JOIN table2
ON table1.column_name=table2.column_name;
24
FULL OUTER JOIN table2
ON table1.column_name=table2.column_name;
Post Lab
Assignm
ent (If
Any)
Experiment 7
Title Subqueries
Objectiv Study and implement the concept of sub queries.
e
Pre- Knowledge of
requisite
● ORACAL COMMANDS
Algorith Subqueries:- A subquery is a form of an SQL statement that appears inside
m another SQL statement. It also termed as nested query. The statement
containing a subquery called a parent statement. The rows returned bu the
/Theory subquery are use by the following statement.
Syntax
Union Clause:
25
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
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
26
Syntax:
FROM tablename ;
MINUS
FROM tablename ;
Post Lab
Assignm
ent (If
Any)
Experiment 8
Title Control languages
Objectiv Study and implement the concept of Data Control Language (DCL),
e Transaction Control Language (TCL).
Pre- Knowledge of
requisite
● ORACAL COMMANDS
Algorith TCL command
m
Transaction Control Language(TCL) commands are used to manage transactions in
/Theory 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
Commit command is used to permanently save any transaaction into database.
Following is Commit command's syntax,
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.
Following is Rollback command's syntax,
Savepoint command
savepoint command is used to temporarily save a transaction so that you
27
can rollback to that point whenever necessary.
Following is savepoint command's syntax,
Syntax commit;
rollback to savepoint-name;
savepoint savepoint-name;
Post Lab
Assignm
ent (If
Any)
Experiment 9
Title Views
Objectiv Study of Simple and Complex View.
e
Pre- Knowledge of
requisite
● ORACLE COMMANDS
Algorith
m CREATE VIEW Statement
/Theory In SQL, a view is a virtual table based on the result-set of an SQL statement.
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
28
Syntax:-
SELECT newcolumnname….
FROM tablename
WHERE columnname=expression_list;
Syntax:-
FROM viewname
Destroying a view-
Syntax:-
Post Lab
Assignm
ent (If
Any)
Experiment 10
Title PL/SQL Program for Addition of Two numbers
Objectiv PL/SQL Control Structure provides conditional tests, loops, flow control
and branches that let to produce well-structured programs.
29
e
Pre- Knowledge of SQL
requisite
Algorith STEP 1: Start
m STEP 2: Initialize the necessary variables.
STEP 3: Develop the set of statements with the essential operational
/Theory parameters.
STEP 4: Specify the Individual operation to be carried out.
STEP 5: Execute the statements.
STEP 6: Stop.
Syntax SQL>set serveroutput on
SQL>declare
1 a number;
2 b number;
3 c number;
4 begin
5 a: =&a;
6 b: =&b;
7 c: =a+b;
8 dbms_output.put_line ('sum of'||a||'and'||b||'is'||c);
9 end;
10 /
INPUT
Enter value for a: 23
old 6: a:=&a;
new 6: a:=23;
Enter value for b: 12
old 7: b:=&b;
new 7: b:=12;
OUTPUT sum of23and12is35
PL/SQL procedure successfully completed.
Post Lab
Assignm
ent (If
Any)
Experiment 11
Title PL/SQL block for greatest of three numbers using IF AND ELSEIF
30
STEP 5: Stop
Objectiv PL/SQL Control Structure provides conditional tests, loops, flow control
e
and branches that let to produce well-structured programs.
31
SQL> declare
2 n number;
3 sum1 number default 0;
4 end value number;
5 begin
6 end value:=&end value;
7 n:=1;
8 for n in 1..endvalue
9 loop
10 if mod(n,2)=1
11 then
12 sum1:=sum1+n;
13 end if;
14 end loop;
15 dbms_output.put_line('sum ='||sum1);
16 end;
17 /
INPUT
Enter value for end value: 4
old 6: end value:=&end value;
new 6: end value:=4;
OUTPUT sum =4
PL/SQL procedure successfully completed.
Post Lab
Assignm
ent (If
Any)
Experiment 13
Title PL/SQL Procedure for GCD Numbers
Post Lab
Assignm
ent (If
Any)
Experiment 15
Title FUNCTION TO FIND FACTORIAL
Objectiv To find factorial using function
e
Pre- Knowledge of SQL
requisite
Algorith Input An integer.
34
m Output Factorial of given number.
Factorial(num)
/Theory 1 if (num=0 or num=1) then.
2 fact = 1;
3 else.
4 for i 1 to n.
Syntax SQL> create or replace function fact(n number)
2 return number is
3 i number(10);
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
Assignm
ent (If
Any)
35