Professional Documents
Culture Documents
Manual New 2015
Manual New 2015
1
1. IN0TRODUCTION TO DBMS
DATA BASE:
Data base is a collection of related data. Data means known facts that can be recorded
and has implicit meaning.
DBMS:
A database management system (DBMS) is a collection of programs that enables
users to create and maintain a database. The DBMS is hence a general-purpose software
system that facilitates the process of defining, constructing and manipulating database for
various applications.
CHARACTERISTICS OF DBMS:
Self describing name of the data base systems.
Insulation between programs and data abstraction.
Support of multiple views of the data.
Sharing of data and multi user transaction processing.
ADVANTAGES OF DBMS:
Controlling redundancy.
Restricting unauthorized access.
Providing persistent storage for program objects and data structures.
Permitting inferencing and actions using rules
Providing multiple user interfaces.
Representing complex relationships among data.
Enforcing integrity constraints.
Providing backup and recovery.
2
ENTITY - RELATIONSHIP MODEL:
ENTITY TYPE:
An entity type defines a collection of entities that have the same attributes. Each
entity type in the database is described by its name and attributes.
ENTITY SET:
The collection of all entities of a particular entity type in the data base at any point in
time is called an entity set. The entity set is usually referred to using the same name as the
entity type.
ATTRIBUTES:
Each entity has attributes- the particular properties that describe it.
TYPE OF ATTRIBUTES:
SINGLE- VALUE VERSUS MULTI-VALUED ATTRIBUTES:
Most attributes have a single value for a particular entity; such attributes are called
single valued. For example age is a single valued attribute of person.
An attribute can have many values for a single entity such attributes are called as
multi valued attributes. For example DEGREE of a person.
NULL VALUE:
The value if it is not specified is called as NULL value. The NULL value is not equal
to zero. It may be unknown, not available, and not applicable. For example TELEPHONE
NUMBER of a person.
3
COMPILERS:
1. DDL COMPILER:
DDL Compiler processes schema definition specific in DDL and stores the description
in the catalog.
2. QUERY COMPILER:
Query Compiler handles the interactive queries. It analyses a query and then generates
calls to the runtime processor for executing the request.
3. PRE COMPILER:
Pre Compiler extracts DML commands from an application program written in a host
programming language. These DML commands compiler for compilation and the rest of the
programs is sent to the host programming compilers. The object codes from both compilers
are linked, whose execution code calls to the run time database processors.
4
2. DATA DEFINITION LANGUAGE (DDL) COMMANDS
AIM:
To perform DDL Commands like Create, Alter and Drop on the database named employee for
DDL COMMANDS:
1. CREATE:
2. ALTER
Syntax:
a. ADD:
b. MODIFY:
3. DROP
DATABASE DESCRIPTION:
6
3. DATA MANIPULATION LANGUAGE (DML) COMMANDS
AIM:
DML COMMANDS:
1. INSERT:
2. UPDATE:
Global Updation:
3. DELETE:
2. Increment the basic pay of all the employees by 10% of their basic pay.
DATABASE DESCRIPTION
7
Age Int --
Address Varchar 20
To create a student detail database and perform DQL commands like Select on the
database.
DQL COMMANDS:
i. AND
ii. OR
iii. NOT
i. BETWEEN
AND <Value2>;
8
ii. NOT BETWEEN
Select * from <table name> where <column name> IN (value1, value2, ………);
Select * from <table name> where <column name> NOT IN (value1, value2 …);
Create a student detail database with roll number, name, date of birth, course, department,
semester, percentage.
Insert 5 records into the database and perform the following operations.
5. Select roll number and name of all records sorted in order by percentage.
7. Select name, course and semester of all students belonging to IT & CSE departments.
9. Select name, percentage of all students with percentage between 85 & 90.
10. Select name, course of all students whose department is in IT, CSE & CIVIL.
11. Select name, course for all students whose department is not in IT, CSE, ECE.
12. Select all records where name is start with alphabet “M”.
13. Select roll number and eid from student and employee.
14. Select departments that are common in students details and employee tables.
9
DATABASE DESCRIPTION
Table Name: student details
Field Name Data type Width
Rno Int --
Sname Varchar 15
DOB Date --
Course Varchar 6
Dept Varchar 4
Sem Varchar 3
Per decimal 10,2
To create student database and perform TCL commands like Commit on the database.
TCL COMMANDS:
Commit
Rollback
3. SAVEPOINT
Savepoint <name>;
Rollback to <name>;
1. In the student database make the transaction as permanent using Commit command.
3. Select a point and implement Savepoint command which is later rollbacked to.
DATABASE DESCRIPTION
Table Name: student details
10
Field Name Data type Width
Rno Int --
Sname Varchar 15
DOB Date --
Course Varchar 6
Dept Varchar 4
Sem Varchar 3
Per Decimal 6,2
To create a library database and perform group functions like select on the database and
perform character functions, numeric functions, date functions and other functions.
GROUP FUNCTIONS:
1. AVG ()
2. SUM ()
3. MAX ()
4. MIN ()
5. COUNT ()
CHARACTER FUNCTIONS:
1. INITCAP(STR)
2. LOWER(STR)
3. UPPER(STR)
9. TRANSLATE
10. SUBSTR
NUMERIC FUNCTIONS:
1. ABS
2. CEIL
3. FLOOR
4. SQRT
5. SIN
6. COS
7. EXP
12
8. POWER
9. ROUND
10. TRUNCATE
11. MOD
DATE FUNCTIONS:
1. ADD – MONTHS
2. LAST – DAY
3. NEXT – DAY
4. MONTHS BETWEEN
5. GREATEST
6. ROUND
7. SYS DATE
OTER FUNCTIONS:
1. TO_CHAR
2. TO_DATE
13
3. TO_NUMBER
MISCELLANEOUS FUNCTION:
1. UID
Select UID;
2. USER
Select USER;
3. NVL
I. Create a library database with book name, author name, access code, date of access,
2. Select the name of the book with maximum price in the given database.
5. Print the total (total cost of all the books) estimate of the library book.
14
III. Execute the following
4. Return the integer value corresponding to the user currently logged in.
15
DATABASE DESCRIPTION:
Table Name: Library
7. CONSTRAINTS ON TABLE
AIM
To create databases to implement the constraints or conditions on tables.
CONSTRAINTS:
1. NOT NULL
i. Create table <table name> (field1 datatype(size) NOT NULL);
ii. Create table <table name> (field1 datatype(size) constraint <constraint
name> NOT NULL);
2. PRIMARY
i. Create table <table name> (field1 datatype(size) PRIMARY);
ii. Create table <table name> (field1 datatype(size) constraint <constraint
name> PRIMARY);
3. UNIQUE
i. Create table <table name> (field1 datatype(size) UNIQUE);
ii. Create table <table name> (field1 datatype(size) constraint <constraint
name> UNIQUE);
4. DEFAULT
Create table <table name> (field1 datatype(size) DEFAULT ‘default value’);
5. CHECK
Create table <table name> (field1 datatype (size) CHECK <condition>);
6. FOREIGN KEY CONSTRAINT
Create table <table name> (field1 datatype (size) REFERENCES fieldname of
table1 <table name>);
16
CONSTRAINTS IMPLEMENTATIONS TO BE PERFORMED:
1. Create an item table with the item name, item code and quantity on hand.
a. Create a constraint so that duplication is not allowed in the item code.
b. Both duplication and null values should not be accepted.
c. Set default value zero to quantity on hand.
d. Always the value of quantity on hand must be greater than 50.
2. Create one more table orders with order number, item code and quantity required as
fields. The condition is that the order of an item can be placed only when that item is
available on the item table.
DATABASE DESCRIPTION:
17
3. SELF JOIN:
Select table1.field, table2.field. ………. from table1 WHERE <condition>
4. OUTER JOIN:
a. LEFT OUTER JOIN:
Select table1.field, table2.field. ………. from table1, table2 WHERE
<table.field (+) = table.field>
b. RIGHT OUTER JOIN:
Select table1.field, table2.field. ………. from table1, table2 WHERE
<table.field = (+) table.field>
5. GROUP BY:
Select field1, field2, aggregate fun (field) FROM <table name> WHERE <condition>
GROUPBY field;
JOINS TO BE PERFORMED:
1. Select the products that are ordered by client ‘Karthik’;
2. Select list of clients who placed orders on ‘keyboard’.
3. Select names of products whose quantity on hand is greater than quantity required by
customer.
4. Select name of employee and manager to the corresponding employee.
5. Select the salary and balance of an employee using left outer join.
6. Select the salary and balance of an employee using right outer join.
7. Select number of books accessed by student B.
8. Select number of books accessed by each student.
9. Select the total quantity of orders placed for each product.
10. Select total amount to be paid by each client.
11. Select total number of products ordered by each client.
DATABASE DESCRIPTION:
18
Table Name: PRODUCT
9. SUBQUERIES IN SQL
AIM
To develop databases to implement SubQueries.
COMMANDS
i. Select * from <table name> WHERE fieldname = (Select fieldname FROM
<table name>);
19
ii. Select * from <table name> WHERE fieldname IN (Select fieldname FROM
<table name>);
SYNTAX FOR OPERATORS IN SUBQUERIES
i. Select * from table1 WHERE t1.value > operator (Select * from table2 where
t2.value <condition>);
OPERATIONS TO BE PERFORMED:
1. Execute the following
Create 3 tables
i. Client with clno, cname, city
ii. Product with pno, pdesc, price, quantity on hand
iii. Sorder with sno, rno, clno and quantity required.
Perform the following operations
iv. Retrieve all clients who placed orders on ‘mouse’.
v. Retrieve all products ordered by ‘Karthik’;
vi. Retrieve all the products ordered by all clients except ‘Karthik’;
2. Execute the following
Create 3 database with the following columns
i. Book with codeno, bname, authorname, pname, price
ii. Student with sid, sname, semester, branch
iii. Library with codeno, sid, date of access, date of return.
Perform the following operations
iv. Retrieve all the books accessed by student ‘S’;
v. Retrieve the details of students who accessed books on DBMS.
vi. Retrieve the details of books ordered on any date.
vii. Retrieve the name and author of the book accessed by 3rd semester
MBA students.
viii. Retrieve the book accessed by students of all departments other than
‘MBA’.
ix. List the details of students who accessed books worth Rs.500 and
above.
x. List the students who accessed books on all publishers other than
‘PHI’.
xi. Retrieve the names of students who accessed books with author
starting with the letter ‘S’.
20
DATABASE DESCRIPTION:
21
Table Name: STUDENT
10. VIEWS
AIM
To develop databases and perform various view operations.
SYNTAX
VIEWS
1. ROW SUBSET VIEW
Create [OR OPTIONAL] view <view name> AS select * from <table name>
where <condition>;
2. COLUMN SUBSET VIEW
Create [OR OPTIONAL] view <view name> AS select field1, field2, …… from
<table name> where <condition>;
3. ROW COLUMN SUBSET VIEW
Create [OR REPLACE] view <view name> AS select field1, field2, …… from
<table name> where <condition>;
4. GROUPED VIEW
Create [OR REPLACE] view <view name> AS select aggregate fun (field) field
alias name from <table name> GroupBy fieldname;
5. PARTITIONED VIEW
Create [OR REPLACE] view <view name> AS select * from <table name>
UNION ALL select * from <table name>;
22
6. VIEWS WITH READ ONLY
Create [OR REPLACE] view <view name> AS select * from <table name> with
read only;
7. VIEWS WITH CHECK OPTIONS
Create [OR REPLACE] view <view name> AS select * from <table name> with
check option;
OPEATIONS TO BE PERFORMED
1. Create a table t1 with attributes iname, icode and cost then insert values to it.
2. Create a table t2 with attributes icode, iname, cname, qty and qdelivery then
insert values.
3. Create a row subset view selecting the details of products that are not
delivered.
4. Create a column subset view selecting icode and quantity alone from t2.
5. Create a row column subset view selecting the itemcodes of delivered
products.
6. Create a grouped view showing the total number of orders placed for each
product.
7. Create a partitioned view selecting item name, cost from t1 and customer
name, and quantity from t2.
8. Create a read only view from t1 selecting icode and cost. Show whether the
values can be inserted or updated in the view.
9. Create a check option view from t2 showing only the delivered products list.
Show whether insertion of an undelivered product can be made on this view.
10. Drop the views created.
DATABASE DESCRIPTION:
Table Name: T1
23
Table Name: T2
SYNTAX:
CURSOR DECLARATION:
CURSOR <CURSOR NAME> IS SELECT colname1, colname2 from
<tablename> where <condition>;
OPEN:
OPEN <CURSOR NAME>;
FETCH:
FETCH <CURSOR NAME> into variable name1, variable name2…..;
CLOSE:
CLOSE <CURSOR NAME>;
OPERATIONS TO BE PERFORMED:
24
1. Simulate the banking transaction using ‘CURSORS’.
2. Update the salary of all employees in employee database by 500 using CURSOR
FOR-LOOP.
DATA BASE DESCRIPTION:
TABLE NAME: edetails
OPERATIONS TO BE PERFORMED:
i. In inventory table, check using ‘SIMPLE-IF’ structure whether QOH is > 0
decrement the QOH by 1.
ii. Using employee table check using ‘ELSE – IF’ whether the salary is < 5000 or not
if so increment the basic pay by 5% else by 10% of basic pay.
iii. Given the service no of person, calculate the electricity bill to be paid that person
based on the conditions given below
Consumption Unit Charge per Unit
0 – 100 80 paise / unit
100 – 250 1 Re / unit
250 – 500 Rs. 230 + 120 paise / unit
> 500 Rs. 400 + 150 paise / unit
iv. Using ‘GOTO’ checks whether ‘QOH’ in Item table is < 25 if so add the reorder
level to QOH else perform No Updation.
DATABASE DESCRIPTION:
26
Table Name: EMPLOYEE
FORMAT:
DECLARE
Local variable declaration
BEGIN
Stmts;
27
Raise <exception name>;
When <exception> then
Stmts;
END;
OPERATIONS TO BE PERFORMED:
1. Create a user defined exception in simulation of banking system, that no transactions
to be performed on Saturday and Sunday.
2. Create a user defined exception in inventory database. Raise “stock is not available”
exception if QOH=0.
PRE-DEFINED EXCEPTION:
1. Too few row exception.
2. No-data found exception.
3. Value error exception.
4. Divide by zero error exception.
DATABASE DESCRIPTION:
TABLE NAME: inventory
TABLE NAME: t2
28
Code Number 5
QOH Number 5
Reorder Number 5
29