Database Management System Lab Manual for Student
Database Management System Lab Manual for Student
University Syllabus
Contents:
i. Creation of a database and writing SQL queries to retrieve information from the database.
ii. Performing Insertion, Deletion, Modifying, Altering, Updating and Viewing records based on
conditions.
iii. Creation of Views, Synonyms, Sequence, Indexes, Save point.
iv. Creating an Employee database to set various constraints.
v. Creating relationship between the databases.
vi. Study of PL/SQL block.
vii. Write a PL/SQL block to satisfy some conditions by accepting input from the user.
viii. Write a PL/SQL block that handles all types of exceptions.
ix. Creation of Procedures.
x. Creation of database triggers and functions
xi. Mini project (Application Development using Oracle/ MySQL)
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. Time Table Management System.
h. Hotel Management
Practical #1
View definition-
The SQL DDL includes commands for defining views.
Transaction Control- SQL includes for specifying the beginning and ending of
transactions.
Integrity-
The SQL DDL includes commands for specifying integrity constraints that the
datastored 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.
The SQL DDL allows specification of not only a set of relations but also
informationabout 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.
The security and authorization information for each relation.
Syntax-
CREATE TABLE TABLENAME
[(columnname, columnname, ………)]
AS SELECT columnname, columnname ........ FROM tablename;
OUTPUT:-
Practical #2
Performing insertion, deletion, modification, altering and updating operations on the records
based on conditions.
OUTPUT:-
Q3:- On the basis of above two tables answer the following Questionries:
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 orequal to 5000.
x) List the name, city and state of clients not in the state of „Maharashtra‟.
Practical #3
Deletion Operation:-
A delete query is expressed in much the same way as Query. 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:
+ Addition - Subtraction
* multiplication ** exponentiation
/ Division () Enclosed operation
Logical Operators:
The logical operators that can be used in SQL sentenced are
Pattern Searching:
The most commonly used operation on string is pattern matching
using the operation„like‟ we describe patterns by using two special
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
Syntax:
Avg ([distinct/all]n)
Min return minimum value of expr.
Syntax:
MIN((distinct/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,
columnnameFrom
table
Order by columnname;
OUTPUT:-
Question.1 Using the table client master and product master answer the following
Questionnaires.
Practical .4
The following tasks you can perform through alter table command.
NOTE: Oracle not allow constraints defined using the alter table, if the data
in the table,violates such constraints.
You can also define integrity constraints using the constraint clause in the
ALTER TABLE command. The following examples show the definitions of
several integrityconstraints.
You can drop an integrity constraint if the rule that if enforces is no longer true or
if theconstraint is no longer needed. Drop the constraint using the ALTER
TABLE commandwith the DROP clause. The following examples illustrate the
dropping of integrity constraints.
OUTPUT:-
Q2. Insert the following values into the challan header and challan_details tables:
Practical #5
Objective:- To Implement the restrictions on the table.
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 creationtime. The constraints can
either be placed at column level or at the table level.
Column Level Constraints: If the constraints are defined along with the
column definition, it is called a column level constraint.
Table Level Constraints: If the data constraint attached to a specify cell in atable 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:
Primary Key: primary key is one or more columns is a table used to uniquely identity each row
in the table. Primary key values must not be null and must be unique across the column. A
multicolumn primary key is called composite primary key.
Default value concept: At the line of cell creation a default value can be assignedto it. When
the user is loading a record with values and leaves this cell empty, the DBA will 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,….);
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 primarykey table to have meaning.
Foreign key as a column constraint
Syntax :
Create table table name
(columnname datatype (size) references another table name);
Check Integrity Constraints: Use the check constraints when you need to enforce integrity
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 client_master so that the name is
entered in upper case.
A check constraint on the client_no column of the client
_master so thatno client_no value starts with „c‟
Syntax:
Create table tablename
(columnname datatype (size) CONSTRAINT
constraintname)Check (expression) );
OUTPUT:-
i. 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
Order_status Varchar2 10 Values („in
process‟;‟fulfilled‟;back
order‟;‟canceled
I. Sales_order_details
Column Datatype Size Attributes
Insert the following data into their respective tables using insert statement:
Data for sales_man master table
Salesman_ Salesman Address City Pin State Salamt Tgt_to_get Ytd Remarks
no name code Sales
500001 Kiran A/14 Bom 400002 Mah 3000 100 50 Good
worli bay
500002 Manish 65,nariman Bom 400001 Mah 3000 200 100 Good
bay
500003 Ravi P-7 Bom 400032 Mah 3000 200 100 Good
Bandra bay
500004 Ashish A/5 Bom 400044 Mah 3500 200 150 Good
Juhu bay
(ii)
Data for salesorder table:
S_orderno S_orderdate Client no Dely Bill Salesman no Delay Orderst
type yn date atus
019001 12-jan-96 0001 F N 50001 20-jan- Ip
96
019002 25-jan-96 0002 P N 50002 27-jan- C
96
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
(i)
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
Practical #6
Objective:- To implement the concept of Joins
Joint Multiple Table (Equi Join): Sometimes we require to treat more than one table asthough
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.
1. Cartesian product:-
Consider two table student and
courseSelect B.*,P.*
FROM student B, course P;
2. INNER JOIN:
Cartesian product followed by
selectionSelect B.*,P.*
FROM student B, Course P WHERE
B.course # P.course # ;
Exam:
Select B.*,P.*
From student B RIGHT JOIN course P
B.course# = P course # ;
OUTPUT:-
Practical # 7
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.
OUTPUT:-
Practical #8
SubQueries:- A subQuery is a form of an SQL statement that appears inside another SQL
statement. It also termed as nested Query. The statement containing a subQuery called a parent
statement. The rowsreturned by the subQuery are used 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.
Exam:-
Creating clientmaster table from oldclient_master, table
Syntax:
SELECT
columnname,
columnameFROM
tablename 1
UNION
SELECT columnname,
columnnameFrom
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 :
in both QueriesSyntax:
MINUS CLAUSE:- The user can put together multiple Queries and combine their output
= records
only in
Query one
Syntax:
SELECT columnname, columnnameFROM tablename ;
MINUS
SELECT columnname, columnnameFROM tablename ;
OUTPUT:-
Practical # 9
Syntax (Simple)
CREATE
INDEX
index_nameON
tablename(colu
mn name);
Composite Index:-
CREATE INDEX index_name
ON tablename(columnname,columnname);
Creation of Views:-
Syntax:-
CREATE VIEW viewname AS SELECT
columnname,columnnameFROM tablename
WHERE columnname=expression_list;
OUTPUT:-
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 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;
Example: Write the following code in the PL/SQL block to display message to
userDBMS_OUTPUT.PUT_LINE(„Display user message‟);
The GOTO statement: The goto statement allows you to change the
flow of controlwithin a PL/SQL Block.
OUTPUT:-
19 21 8
b is maximum 21
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.
MINI PROJECT(Sample)
VIVA QUESTIONS