You are on page 1of 50

`

SRM UNIVERSITY
Ramapuram, Chennai- 600089.

FACULTY OF ENGINEERING AND TECHNOLOGY


Department of Computer Science & Engineering

LAB MANUAL
CS1037 DATABASE MANAGEMENT
SYSTEMS LAB
CLASS

B.Tech. [U.G]

YEAR / SEM

III Year / V Semester

SOFTWARE REQUIREMENT

ORACLE9i & VB 6.0

PREPARED BY
S.No.
1.
2.

Staff Name
Mrs.Devahema.D
Mr.K.Rajarajan

Designation
AP(OG)
AP(OG)

Signature

Approved By
HOD/CSE

SYLLABUS
CS1037 DATABASE MANAGEMENT SYSTEMS LAB
Prerequisite
CS0201

L T P C
0 0 3 2

PURPOSE
This laboratory course gives a thorough understanding of the concepts of database design
model and its applications. It also gives a comprehensive understanding of using a query
language.

INSTRUCTIONAL OBJECTIVES
1. Designing a database
2. Using DDL and DML commands
3. Backing up of files

LIST OF EXPERIMENTS
1. Data Definition Language (DDL) commands in RDBMS
2. Data Manipulation Language (DML) and Data Control Language (DCL)
3. High level language extensions with cursors
4. High level language extension with Triggers
5. Procedures and Functions
6. Embedded SQL
7. Database design using E-R model and Normalization
8. Design and implementation of payroll processing system
9. Design and implementation of Banking system
10. Design and implementation of Library Information System
11. Design and implementation of Student Information System
12. Automatic Backup of Files and Recovery of Files

TABLE OF CONTENTS
EX.
NO.

NAME OF THE EXPERIMENT

PAGE.
NO.

STUDY EXPERIMENT SQL


1

Data Definition Language (DDL) commands in RDBMS

Data Manipulation Language (DML) and Data Control


12

Language (DCL)

High level language extensions with cursors

24

High level language extension with Triggers

25

Procedures and Functions

27

Embedded SQL

29

Database design using E-R model and Normalization

30

Design and implementation of payroll processing system

39

Design and implementation of Banking system

41

10

Design and implementation of Library Information System

43

11

Design and implementation of Student Information System

45

12

Automatic Backup of Files and Recovery of Files

47

STUDY EXPERIMENT-SQL
Structured Query Language (SQL) is the language used to manipulate relational databases.
SQL is tied very closely with the relational model.
In the relational model, data is stored in structures called relations or tables. Each table has
one or more attributes or columns that describe the table. In relational databases, the table is
the fundamental building block of a database application. Tables are used to store data on
Employees, Equipment, Materials, Warehouses, Purchase Orders, Customer Orders, etc.
Columns in the Employee table, for example, might be Last Name, First Name, Salary, Hire
Date, Social Security Number, etc.
SQL statements are issued for the purpose of:

Data definition - Defining tables and structures in the database (DB).


Data manipulation - Inserting new data, Updating existing data, Deleting existing
data, and Querying the Database ( Retrieving existing data from the database).

Another way to say this is the SQL language is actually made up of 1) the Data Definition
Language (DDL) used to create, alter and drop scema objects such as tables and indexes, and
2) The Data Manipulation Language (DML) used to manipulate the data within those schema
objects.
The SQL language has been standardized by the ANSI X3H2 Database Standards
Committee. Two of the latest standards are SQL-89 and SQL-92. Over the years, each vendor
of relational databases has introduced new commands to extend their particular
implementation of SQL. Oracle's implementation of the SQL language conforms to the basic
SQL-92 standard and adds some additional commands and capabilities.

SQL Statements
The following is an alphabetical list of SQL statements that can be issued against an Oracle
database. These commands are available to any user of the Oracle database. Emphasized
items are most commonly used.

ALTER - Change an existing table, view or index definition


AUDIT - Track the changes made to a table
COMMENT - Add a comment to a table or column in a table
COMMIT - Make all recent changes permanent
CREATE - Create new database objects such as tables or views
DELETE - Delete rows from a database table
DROP - Drop a database object such as a table, view or index
GRANT - Allow another user to access database objects such as tables or views
INSERT - Insert new data into a database table
No AUDIT - Turn off the auditing function
REVOKE - Disallow a user access to database objects such as tables and views
ROLLBACK - Undo any recent changes to the database
SELECT - Retrieve data from a database table
4

UPDATE - Change the values of some data items in a database table

Some examples of SQL statements follow. For all examples

SQL Data Definition Language


In this section, the basic SQL Data Definition Language statements are introduced and their
syntax is given with examples.
An Oracle database can contain one or more schemas. A schema is a collection of database
objects that can include: tables, views, indexes and sequences
Any object in the database must be created in only one schema. The object name is prefixed
by the schema name as in: schema.object_name

By default, all objects are created in the user's own schema. For example, when JONES
creates a database object such as a table, it is created in her own schema. If JONES creates an
EMPLOYEE table, the full name of the table becomes: JONES.EMPLOYEE. Thus database
objects with the same name can be created in more than one schema. This feature allows each
user to have their own EMPLOYEE table, for example.
Database objects can be shared among several users by specifying the schema name. In order
to work with a database object from another schema, a user must be granted authorization.
See the section below on GRANT and REVOKE for more details.
Please note that many of these database objects and options are not available under Personal
Oracle Lite. For example, foreign key constraints are not supported. Please see the on-line
documentation for Personal Oracle Lite for more details.

Create, Modify and Drop Tables, Views and Sequences


SQL*Plus accepts SQL statements that allow a user to create, alter and drop table, view and
sequence definitions. These statements are all standard ANSI SQL statements with the
exception of CREATE SEQUENCE.

ALTER TABLE - Change an existing table definition. The table indicated in the
ALTER statement must already exist. This statement can be used to add a new
column or remove an existing column in a table, modify the data type for an existing
column, or add or remove a constraint.
ALTER TABLE has the following syntax for adding a new column to an existing
table:

ADD ( ) ;
Another ALTER TABLE option can change a data type of column. The syntax is:
ALTER TABLE

MODIFY ( ) ;

`
Finally, ALTER TABLE can also be used to add a constraint to a table such as for a
PRIMARY KEY, FOREIGN KEY or CHECK CONSTRAINT. The syntax to add a
PRIMARY KEY is:
ALTER TABLE

ADD CONSTRAINT PRIMARY KEY ();


The syntax to add a FOREIGN KEY constraint is:
ALTER TABLE
ADD CONSTRAINT
FOREIGN KEY ()
REFERENCES (column-name);

In Oracle, you must use an ALTER TABLE statement to define a composite PRIMARY
KEY (a key made up of two or more columns).
NOTE: In Oracle, there is no single command to drop a column of a table. In order to drop a
column from a table, you must create a temporary table containing all of the columns and
records that will be retained. Then drop the original table and rename the temporary table to
the original name. This is demonstrated below in the section on Creating, Altering and
Dropping Tables.
CREATE TABLE - Create a new table in the database. The table name must not already
exist. CREATE TABLE has the following syntax:
CREATE TABLE
(
,
,
. . .
) ;

An alternate syntax can be used to create a table with a subset of rows or columns from an
existing table.
CREATE TABLE

AS ;

DROP TABLE - Drop a table from the database. The table name must already exist in the
database. The syntax for the DROP TABLE statement is:
DROP TABLE ;

CREATE INDEX - Create a new Index that facilitates rapid lookup of data. An index is
typically created on the primary and/or secondary keys of the table. The basic syntax for the
CREATE INDEX statement is:
CREATE INDEX
ON ();

DROP INDEX - Drop an index from the database. The syntax for the
DROP INDEX statement is:
DROP INDEX

CREATE SEQUENCE - Create a new Oracle Sequence of values. The new sequence name
must not exist. CREATE SEQUENCE has the following syntax:
CREATE SEQUENCE
INCREMENT BY
START WITH
MAXVALUE
CYCLE ;

DROP SEQUENCE - Drop an Oracle Sequence. The sequence name must exist. DROP
SEQUENCE has the following syntax:
DROP SEQUENCE

`
CREATE VIEW - Create a new view based on existing tables in the database. The table
names must already exist. The new view name must not exist. CREATE VIEW has the
following syntax:
CREATE VIEW AS;

Where sql select statement is in the form:


SELECT

FROM

WHERE
Additional information on the SELECT statement and SQL queries can be found in the next
section.
Note that an ORDER BY clause may not be added to the sql select statement when defining a
view.
In general, views are read-only. That is, one may query a view but it is normally the case that
views can not be operated on with INSERT, UPDATE or DELETE. This is especially true in
cases where views joing two or more tables together or when a view contains an aggregate
function.
DROP VIEW - Drop a view from the database. The view name must already exist in the
database. The syntax for the DROP VIEW command is:
DROP VIEW

In the following section, each of the SQL DDL commands will be discussed in more detail.

Creating, Altering and Dropping Tables


1. VARCHAR2 - Character data type. Can contain letters, numbers and punctuation.
The syntax for this data type is: VARCHAR2(size) where size is the maximum number
of alphanumeric characters the column can hold. For example VARCHAR2(25) can
hold up to 25 alphanumeric characters. In Oracle8, the maximum size of a
VARCHAR2 column is 4,000 bytes.
The VARCHAR data type is a synonym for VARCHAR2. It is recommended to use
VARCHAR2 instead of VARCHAR.
2. NUMBER - Numeric data type. Can contain integer or floating point numbers only.
The syntax for this data type is: NUMBER(precision, scale) where precision is the
total size of the number including decimal point and scale is the number of places to
the right of the decimal. For example, NUMBER(6,2) can hold a number between 999.99 and 999.99.
3. DATE - Date and Time data type. Can contain a date and time portion in the format:
DD-MON-YY HH:MI:SS. No additional information is needed when specifying the
DATE data type. If no time component is supplied when the date is inserted, the time
of 00:00:00 is used as a default. The output format of the date and time can be
modified to conform to local standards.
4. RAW - Free form binary data. Can contain binary data up to 255 characters. Data
type LONG RAW can contain up to 2 gigabytes of binary data. RAW and LONG
7

`
RAW data cannot be indexed and can not be displayed or queried in SQL*Plus. Only
one RAW column is allowed per table.
5.
LOB - Large Object data types. These include BLOB (Binary Large OBject) and
CLOB (Character Large OBject). More than one LOB column can appear in a table.
These data types are the prefferred method for storing large objects such as text
documents (CLOB), images, or video (BLOB).

RESULT
Thus the DDL and DML commands were studied in detail.

Ex: no: 1
DATA DEFINITION LANGUAGE (DDL) COMMANDS IN RDBMS
AIM
To execute the DDL commands in SQL plus.
1. Create a student table with id,name,dob,address,age and deptid.
SQL> create table student_data(stu_id number,stu_name varchar2(20),stu_dob date,stu_addr
varchar2(20),stu_age number, dept_id number(20));
Table created.
2. Display the structure of the student table.
SQL> desc student_data;
Name
Null?
----------------------STU_ID
STU_NAME
STU_DOB
STU_ADDR
STU_AGE
DEPT_ID

Type
----------NUMBER
VARCHAR2 (20)
DATE
VARCHAR2 (20)
NUMBER
NUMBER (20)

3. Add a new attribute gender into the created student table.


SQL> alter table student_data add (gender varchar (5));
Table altered.
4. Modify the datatype of the deptid attribute in the student table.
SQL> alter table student_data modify (dept_id number);
Table altered.
5. Remove the column deptid from the student table.
SQL> alter table dept_data drop column dept_id;
Table altered.
6. Mark the columns which are not in use as unused
SQL> alter table student_data set unused column stu_age;
Table altered.
9

`
7. Remove the unused columns from the student table.
SQL> alter table student_data drop unused columns;
Table altered.

8. Create a department table with deptid,dept_name and strength in each dept.


SQL> create table dept_data (dept_id number, dept_name varchar2 (20),dept_strength
number);
Table created.
9. Create a staff profile table with id,name,deptid, dept_name,qualification and subject
handled.
SQL> create table staff_data (staff_id number,staff_name varchar2(20),dept_id number,
staff_quali varchar2(10),sub_handled varchar2(30),dept_name varchar2(20));
Table created.
10. Display the structure of the modified student table.
SQL> desc student_data;
Name
Null?
----------------------STU_ID
STU_NAME
STU_DOB
STU_ADDR
DEPT_ID
GENDER

Type
---------NUMBER
VARCHAR2(20)
DATE
VARCHAR2(20)
NUMBER
VARCHAR2(5)

11. Display the structure of the department table.


SQL> desc dept_data;
Name
-------------------DEPT_ID
DEPT_NAME
DEPT_STRENGTH

Null? Type
-------- -----------NUMBER
VARCHAR2(20)
NUMBER

12. Display the structure of the staff profile table.

SQL> desc staff_data;


10

`
Name
Null? Type
----------------------------------------- -------- ---------------------------STAFF_ID
NUMBER
STAFF_NAME
VARCHAR2(20)
DEPT_ID
NUMBER
STAFF_QUALI
VARCHAR2(10)
SUB_HANDLED
VARCHAR2(30)
DEPT_NAME
VARCHAR2(20)

RESULT
Thus the DDL commands were executed successfully and verified.

11

Ex.no:2
DATA MANIPULATION LANGUAGE (DML) AND DATA CONTROL
LANGUAGE (DCL)
AIM
To execute the DML commands in SQL plus.

1. Populate the created student table with related data.


SQL> insert into student_data
values(&stu_id,'&stu_name','&stu_dob','&stu_addr','&dept_id','&gender'
);
Enter value for stu_id: 1001
Enter value for stu_name: abisha
Enter value for stu_dob: 31-jan-1990
Enter value for stu_addr: chennai
Enter value for dept_id: 501
Enter value for gender: f
old 1: insert into student_data
values(&stu_id,'&stu_name','&stu_dob','&stu_addr','&dept_id','&gen
new 1: insert into student_data values(1001,'abisha','31-jan-1990','chennai','501','f')
1 row created.
SQL> /
Enter value for stu_id: 1002
Enter value for stu_name: chandru
Enter value for stu_dob: 4-mar-1990
Enter value for stu_addr: vellore
Enter value for dept_id: 501
Enter value for gender: m
old 1: insert into student_data
values(&stu_id,'&stu_name','&stu_dob','&stu_addr','&dept_id','&gen
new 1: insert into student_data values(1002,'chandru','4-mar-1990','vellore','501','m')
1 row created.
SQL> /
Enter value for stu_id: 2001
Enter value for stu_name: aakash
Enter value for stu_dob: 5-may-1989
Enter value for stu_addr: madurai
Enter value for dept_id: 401
Enter value for gender: m
old 1: insert into student_data
values(&stu_id,'&stu_name','&stu_dob','&stu_addr','&dept_id','&gen
new 1: insert into student_data values(2001,'aakash','5-may-1989','madurai','401','m')

12

`
1 row created.
SQL> /
Enter value for stu_id: 2003
Enter value for stu_name: divya
Enter value for stu_dob: 10-aug-1991
Enter value for stu_addr: trichy
Enter value for dept_id: 401
Enter value for gender: f
old 1: insert into student_data
values(&stu_id,'&stu_name','&stu_dob','&stu_addr','&dept_id','&gen
new 1: insert into student_data values(2003,'divya','10-aug-1991','trichy','401','f')
1 row created.
SQL> /
Enter value for stu_id: 3001
Enter value for stu_name: akshara
Enter value for stu_dob: 15-jul-1991
Enter value for stu_addr: erode
Enter value for dept_id: 601
Enter value for gender: f
old 1: insert into student_data
values(&stu_id,'&stu_name','&stu_dob','&stu_addr','&dept_id','&gen
new 1: insert into student_data values(3001,'akshara','15-jul-1991','erode','601','f')
1 row created.
SQL> /
Enter value for stu_id: 3007
Enter value for stu_name: prasad
Enter value for stu_dob: 23-nov-1989
Enter value for stu_addr: nagercoil
Enter value for dept_id: 601
Enter value for gender: m
old 1: insert into student_data
values(&stu_id,'&stu_name','&stu_dob','&stu_addr','&dept_id','&gen
new 1: insert into student_data values(3007,'prasad','23-nov-1989','nagercoil','601','m')
1 row created.
14. Display the populated student information table.
SQL> select * from student_data;
STU_ID
STU_NAME
GENDE
----------------------------1001
abisha
1002
chandru

STU_DOB

STU_ADDR

DEPT_ID

---------

--------------------

----------

----

31-JAN-90
04-MAR-90

chennai
vellore

501
501

f
m
13

`
2001
2003
3001
3007

aakash
divya
akshara
prasad

05-MAY-89 madurai
10-AUG-91 trichy
15-JUL-91
erode
23-NOV-89 nagercoil

401
401
601
601

m
f
f
m

6 rows selected.
2. Populate the department table.
SQL> insert into dept_data values(&dept_id,'&dept_name',&dept_strength);
Enter value for dept_id: 401
Enter value for dept_name: cse
Enter value for dept_strength: 400
old 1: insert into dept_data values(&dept_id,'&dept_name',&dept_strength)
new 1: insert into dept_data values(401,'cse',400)
1 row created.
SQL> /
Enter value for dept_id: 501
Enter value for dept_name: IT
Enter value for dept_strength: 380
old 1: insert into dept_data values(&dept_id,'&dept_name',&dept_strength)
new 1: insert into dept_data values(501,'IT',380)
1 row created.
SQL> /
Enter value for dept_id: 601
Enter value for dept_name: ECE
Enter value for dept_strength: 350
old 1: insert into dept_data values(&dept_id,'&dept_name',&dept_strength)
new 1: insert into dept_data values(601,'ECE',350)
1 row created.
3. Display the department information table.
SQL> select * from dept_data;
DEPT_ID DEPT_NAME
DEPT_STRENGTH
---------- -------------------- ------------401 cse
400
501 IT
380
601 ECE
350

4. Populate the staff profile table with related datas.


SQL> insert into staff_data
values(&staff_id,'&staff_name',&dept_id,'&staff_quali','&sub_handled','&
14

`
dept_name');
Enter value for staff_id: 111
Enter value for staff_name: padma
Enter value for dept_id: 401
Enter value for staff_quali: M.E
Enter value for sub_handled: TOC,PDC
Enter value for dept_name: cse
old 1: insert into staff_data
values(&staff_id,'&staff_name',&dept_id,'&staff_quali','&sub_handled
new 1: insert into staff_data values(111,'padma',401,'M.E','TOC,PDC','cse')
1 row created.
SQL> /
Enter value for staff_id: 112
Enter value for staff_name: ashok
Enter value for dept_id: 501
Enter value for staff_quali: M.E
Enter value for sub_handled: DS,VP
Enter value for dept_name: it
old 1: insert into staff_data
values(&staff_id,'&staff_name',&dept_id,'&staff_quali','&sub_handled
new 1: insert into staff_data values(112,'ashok',501,'M.E','DS,VP','it')
1 row created.
SQL> /
Enter value for staff_id: 113
Enter value for staff_name: banu
Enter value for dept_id: 601
Enter value for staff_quali: M.E(PhD)
Enter value for sub_handled: DSP,DCF
Enter value for dept_name: ece
old 1: insert into staff_data
values(&staff_id,'&staff_name',&dept_id,'&staff_quali','&sub_handled
new 1: insert into staff_data values(113,'banu',601,'M.E(PhD)','DSP,DCF','ece')
1 row created.
SQL> /
Enter value for staff_id: 114
Enter value for staff_name: nadhan
Enter value for dept_id: 501
Enter value for staff_quali: M.E
Enter value for sub_handled: SE,OS
Enter value for dept_name: it
old 1: insert into staff_data
values(&staff_id,'&staff_name',&dept_id,'&staff_quali','&sub_handled
new 1: insert into staff_data values(114,'nadhan',501,'M.E','SE,OS','it')
1 row created.
15

`
SQL> /
Enter value for staff_id: 115
Enter value for staff_name: terencya
Enter value for dept_id: 601
Enter value for staff_quali: M.E(PhD)
Enter value for sub_handled: MP,ES
Enter value for dept_name: ece
old 1: insert into staff_data
values(&staff_id,'&staff_name',&dept_id,'&staff_quali','&sub_handled
new 1: insert into staff_data values(115,'terencya',601,'M.E(PhD)','MP,ES','ece')
1 row created.
SQL> /
Enter value for staff_id: 116
Enter value for staff_name: shanaz
Enter value for dept_id: 401
Enter value for staff_quali: M.E
Enter value for sub_handled: DBMS,CD
Enter value for dept_name: cse
old 1: insert into staff_data
values(&staff_id,'&staff_name',&dept_id,'&staff_quali','&sub_handled
new 1: insert into staff_data values(116,'shanaz',401,'M.E','DBMS,CD','cse')
1 row created.

5. Display the staff profile table.


SQL> select * from staff_data;
STAFF_ID STAFF_NAME DEPT_ID STAFF_QUAL SUB_HANDLED DEPT_NAME
-------------- ------------------- ----------- ------------------- ---------------------- ----------------111
padma
401
M.E
TOC,PDC
cse
112

ashok

501

M.E

DS,VP

it

113

banu

601

M.E(PhD)

DSP,DCF

ece

114

nadhan

501

M.E

SE,OS

it

115

terencya

601

M.E(PhD)

MP,ES

ece

116

shanaz

401

M.E

DBMS,CD

cse

6 rows selected.
6. Display the deptid from the department table avoiding duplicates.

16

`
SQL> select distinct dept_id from student_data;
DEPT_ID
---------401
501
601
7. List out the student name and deptid of all the students in the student table.
SQL> select stu_name, dept_id from student_data;
STU_NAME
---------------abisha
chandru
aakash
divya
akshara
prasad

DEPT_ID
-----------501
501
401
401
601
601

6 rows selected.
8. Add a new attribute salary into the staff profile table.
SQL> alter table staff_data add(salary number);
Table altered.
9. Add values for the newly added attribute in the staff profile table.
SQL> update staff_data set salary=30000 where dept_id=401;
2 rows updated.
SQL> update staff_data set salary=35000 where dept_id=601;
2 rows updated.
SQL> update staff_data set salary=30000 where dept_id=501;
2 rows updated.
10. Display the modified staff profile table.
SQL> select * from staff_data;
STAFF_ID STAFF_NAME DEPT_ID STAFF_QUAL SUB_HANDLED DEPT_NAME
SALARY
-------------- ------------------- ------------- ------------------ ---------------------- ----------------- -----------17

`
111
30000
112
30000
113
35000
114
30000
115
35000
116
30000

padma

401

M.E

TOC,PDC

cse

ashok

501

M.E

DS,VP

banu

601

M.E(PhD)

DSP,DCF

ece

nadhan

501

M.E

SE,OS

it

terencya

601

M.E(PhD)

MP,ES

ece

shanaz

401

M.E

DBMS,CD

cse

it

6 rows selected.

11. List the name and salary from staff table with 300rs incrementation.
SQL> select staff_name, salary, salary+300 from staff_data;
STAFF_NAME SALARY SALARY+300
-------------------- ---------- -------------------padma
30000
30300
ashok
30000
30300
banu
35000
35300
nadhan
30000
30300
terencya
35000
35300
shanaz
30000
30300
6 rows selected.
12. Assign a name for the incremented salary as increrment.
SQL> select staff_name,staff_quali, salary+300 "increment" from staff_data;
STAFF_NAME STAFF_QUAL increment
-------------------- ------------------- --------------padma
M.E
30300
ashok
M.E
30300
banu
M.E(PhD)
35300
nadhan
M.E
30300
terencya
M.E(PhD)
35300
shanaz
M.E
30300
6 rows selected.

13. Display the staffname and id for the staff whose salary is above 30000.
18

`
SQL> select staff_id,staff_name from staff_data where salary>30000;
STAFF_ID STAFF_NAME
--------------- -------------------113
banu
115
terencya
14. Display the name and subject handled whose salary is between 30000 and 50000.
SQL> select staff_name, sub_handled from staff_data where salary between 30000 and
35000;
STAFF_NAME
-------------------padma
ashok
banu
nadhan
terencya
shanaz

SUB_HANDLED
---------------------TOC,PDC
DS,VP
DSP,DCF
SE,OS
MP,ES
DBMS,CD

6 rows selected.
15. Display the name and id of the student whose id is 30007.
SQL> select stu_name,dept_id from student_data where stu_id=3007;
STU_NAME DEPT_ID
--------------- -----------prasad
601
16. Display the name ,dob,address of the students whose ids are 401 and 501.
SQL> select stu_name,stu_dob,stu_addr from student_data where dept_id in (401,501);
STU_NAME
-------------------abisha
chandru
aakash
divya

STU_DOB
---------------31-JAN-90
04-MAR-90
05-MAY-89
10-AUG-91

STU_ADDR
-------------------chennai
vellore
madurai
trichy

17. Display the name and id of the student whose name starts with the letter a.
SQL> select stu_name,stu_id from student_data where stu_name like '__a%';
STU_NAME
-------------------chandru
prasad

STU_ID
-------------1002
3007
19

18. List the anme adob and id of the students whose address does not have r as the second
letter and id should not be of 401.
SQL> select stu_name,stu_dob,stu_id from student_data where stu_addr not like '_r%' and
dept_id=401;
STU_NAME STU_DOB
STU_ID
--------------- ----------------- -----------aakash
05-MAY-89
2001
19. Display the name and qualification of the staff whose subject handled does not start
withd.
SQL> select staff_name,staff_quali from staff_data where sub_handled not like 'D%';
STAFF_NAME
-------------------padma
nadhan
terencya

STAFF_QUAL
-------------------------M.E
M.E
M.E(PhD)

20. Display the name of the staff whose id does not range from 111 to 114.
SQL> select staff_name from staff_data where staff_id not between 111 and 114;
STAFF_NAME
-------------------terencya
shanaz
21. Display the name and id of the staff whose id is 111 and salary above 20000.
SQL> select staff_id,staff_name from staff_data where staff_id=111 and salary>20000;
STAFF_ID STAFF_NAME
---------------- -------------------111
padma
22. Display the id and name of the staff whose id is 112 or salary above 35000.
SQL> select staff_id,staff_quali from staff_data where staff_id=112 or salary<35000;

STAFF_ID STAFF_QUAL
---------------- --------------------111
M.E
112
M.E
114
M.E
116
M.E
20

23. Display the name,designation and salary of the staff with some incrementation for HOD,
and Lecturer and for others display the original salary.
SQL> select staff_name,staff_desig,salary, case staff_desig when 'HOD'then salary+600
when 'Lecturer
' then salary+400 else salary end "revised salary" from staff_data;
STAFF_NAME
STAFF_DESI SALARY revised salary
-------------------- ---------- ---------- --------------------------------anne
Lecturer
25000
25400
jasmine
Lecturer
25000
25400
saranya
Sr.Lec
30000
30000
juhi
HOD
40000
40600
aparna
Programer
10000
10000
santhya
Programer
10000
10000
6 rows selected.
24. Display the name,designation and salary of the staff with some incrementation for HOD,
and Lecturer and for others display the original salary.
SQL> select
staff_name,dept_id,staff_quali,staff_desig,salary,decode(staff_desig,'Lecturer',salary+4
00,'HOD',salary+600,'Programer',salary+200,salary)revisedsalary from staff_data;
STAFF_NAME DEPT_ID STAFF_QUAL STAFF_DESI SALARY
REVISEDSALARY
-------------------- ---------- ------------------- ------------------ -------------anne
101
M.E
Lecturer
25000
jasmine
103
M.E
Lecturer
25000
saranya
101
M.E(PhD)
Sr.Lec
30000
juhi
103
PhD
HOD
40000
aparna
101
B.E
Programer
10000
santhya
103
B.E
Programer
10000

------------25400
25400
30000
40600
10200
10200

6 rows selected.

25. Display the name and jobid of the employees whose dob is between 20-jan-85 to 20-nov86 and order the query in descending order by name
SQL> select name,jobid from employee where dob between '20-jan-85' and '20-nov-86'
2 order by name desc;
NAME
JOBID
-------------------- -------------------roopa
programer
jasmine
lecturer
21

`
aparna
anne

programer
lecturer

26. Calculate the minimum salary,total salary,average salary and number of employees using
the aggregate functions.
SQL> select min(salary),count(emp_id),sum(salary),avg(salary) from emp33;
MIN(SALARY) COUNT(EMP_ID) SUM(SALARY)
--------------------------------10000
5
115000

AVG(SALARY)
---------23000

27.Create a query to set the jobid for the empid(124) as the jobid of the empid(112).
SQL> update emp33 set jodid=(select jodid from emp33 where emp_id=112) where
emp_id=124;
1 row updated.
28. Remove the row from the employee table where the id is 112.
SQL> delete from emp33 where emp_id=112;
1 row deleted.
29. Remove the rows from the employee table where the jobid is clerk.
SQL> delete from emp33 where jodid='clerk';
2 rows deleted.
30. Remove all the datas from the employee table.
SQL> delete from emp33;
2 rows deleted.

22

DATA CONTROL LANGUAGE


DCL commands are used to enforce database security in a multiple user database
environment.Two types of DCL commands are GRANT and REVOKE.Only Database
Administrator's or owner's of the database object can provide or remove privileges on a
database object.
DCL COMMANDS

GRANT
SQL GRANT is a command used to provide access or priviledges on the database objects to
the users.
THE Syntax for the GRANT Command is:GRANT privilege_name
ON object_name
TO {user_name|PUBLIC|role_name}
[WITH GRANT OPTION];

privilege_name is the access right or privileg granted to the user.Some of the access
rights are ALL,EXECUTE and SELECT.
object_name is the name of an database object like TABLE,VIEW,STORED PROC
and SEQUENCE.
User_name is the name of the user to whom an access right is being granted.
PUBLIC is used to grant all rights to users.
ROLES are a set of privileges grouped together.
WITH GRANT OPTION allows a user to grant access rights to other users.

REVOKE
The REVOKE command removes user access rights or privileges to the database objects.
THE Syntax for the REVOKE Command
REVOKE privilege_name
ON object_name
FROM {user_name|PUBLIC|role_name}

RESULT
Thus the DML commands were executed successfully and verified.
23

Ex.no:3
HIGH LEVEL LANGUAGE EXTENSIONS WITH CURSORS
AIM
To write a cursors program for calculating the retirement date of the youngest employee
in PL/SQL.
->Create an employee table with name, id, DOB, salary and populate the created
employee table.
PROGRAM
SQL>set serveroutput on;
declare
new_bday date;
nm emp38.name%type;
eid emp38.id%type;
rd date;
cursor find_new_bday is select max(dob) from emp38;
cursor emp_det is select name, id from emp38 where dob=new_bday;
begin
if not find_new_bday%isopen then
open find_new_bday;
end if;
fetch find_new_bday into new_bday;
close find_new_bday;
open emp_det;
fetch emp_det into nm, eid;
dbms_output.put_line ('The youngest employee is '|| nm || ',' || eid);
rd:=add_months (new_bday, 60*12);
dbms_output.put_line('Retirement date is ' || rd);
close emp_det;
end;
/
PL/SQL Procedure executed successfully

OUTPUT
The youngest employee is anadi 5008
Retirement date is 12-jan-2071

RESULT
Thus the retirement date of the youngest employee is calculated and verified
successfully.
24

Ex.no:4
HIGH LEVEL LANGUAGE EXTENSION WITH TRIGGERS
AIM
To create a trigger for displaying the error message if the salary inserted is above 10000
using PL/SQL.
Create an account table with name,id and salary.

PROGRAM
create or replace trigger salary before insert or update on account
referencing new as n for each row
begin
if(:n.sal>10000)then
raise_application_error(-20001,'salary should not be above 10000');
end if;
end;
/
Trigger created

OUTPUT
Insert into account values(john,538,12000);
Insert into account values (john, 538, 12000 )
ORA-06551: line 10, column 2:
PL/SQL: salary should not be above 10000
Create a emp2 table with name,id doj,salary and emp_log table with
empid,log_date,new_salary,action. Populate the first table emp2.

PROGRAM
create or replace trigger log_salary_increase1
before update on emp2
for each row
when(new.sal>10000)
begin
insert into emp_log(empid,log_date,new_salary,action)
values(:new.deptno,sysdate,:new.sal,'new sal');
end;
/
Trigger created.

25

OUTPUT
Insert into emp2 values (Joshua,203,22-nov-2010,20000);
1 row created
Select * from emp_log;
Empid
------203

log_date
new_salary
----------------------5-apr-2010
20000

action
---------newsal

RESULT
Thus the trigger program for inserting values into the emp_log was verified successfully.
26

Ex.no:5
PROCEDURES AND FUNCTIONS
PROCEDURES
AIM
To write a procedure in PL/SQL that displays first name and last name of student
->create table student with fname,lname,sid
PROGRAM
create or replace procedure find_sname
(p_sid NUMBER)
as
p_fname varchar2;
p_lname varchar2;
begin
select fname,lname into p_fname,p_lname from student where sid:=p_sid;
dbms_output.put_line(stud first name||p_fname);
dbms_output.put_line(stud last name||p_lname);
end find_sname;
calling a procedure
declare
begin
find_sname(428);
end;
OUTPUT
stud first name-vikram
stud last name-singh rathore

27

FUNCTIONS
AIM
To write a function in PL/SQL that displays first name of student
->create table student with fname,lname,sid
PROGRAM
create or replace function find_sname
(p_sid NUMBER) return number
as
p_fname varchar2;
begin
select fname into p_fname from student where sid=p_sid;
return p_fname;
end find_sname;
calling a function
declare
fname1 varchar2;
sid1
number:='&input_idno';
begin
fname1:=find_sname(sid1);
dbms_output.put_line(stud first name||fname1);
end;
OUTPUT
stud first name-vikram

RESULT
Thus the procedures and functions in PL/SQL are created and executed successfully.
28

Ex.no:6
EMBEDDED SQL
AIM
To write a java program to embed SQL with java
import java.io.*;
import java.sql.*;
class embeddedSQL
{
public static void main(String args[])
{
try
{
Class.for.Name(sun.jdbc.odbc.JdbcOdbcDriver);
}
catch(ClassNotFoundException ie)
{
System.out.println(le);
}
try{
Connection con=DriverManager.getConnection(jdbc:odbc:hhh);
Statement st=con.createStatement();
ResultSet rs=st.executeQuery(select * from table10);
while(rs.next())
{
System.out.println(rs.getInt(1)+\t);
System.out.println(rs.getString(2)+\t);
System.out.println( );
}}
catch(SQLException s)
{
System.out.println(s);}}}
OUTPUT
D:\db
D:\db>javac embeddedSQL.java
D:\db>java embeddedSQL
1 vikram
2 rancho

RESULT
Thus the queries were executed successfully.
29

Ex.no:7
DATABASE DESIGN USING E-R MODEL AND NORMALIZATION
E-R MODEL
AIM
This document is an entity-relationship diagram, or ERD, for a system to manage
electronic resources. An ERD is a model that identifies the concepts or entities that exist in a
system and the relationships between those entities. An ERD is often used as a way to
visualize a relational database: each entity represents a database table, and the relationship
lines represent the keys in one table that point to specific records in related tables. ERDs may
also be more abstract, not necessarily capturing every table needed within a database, but
serving to diagram the major concepts and relationships. This ERD is of the latter type,
intended to present an abstract, theoretical view of the major entities and relationships needed
for management of electronic resources. It may assist the database design process for an eresource management system, but does not identify every table that would be necessary for
an electronic resource management database.
This ERD should be examined in close consultation with other components of the Report
of the DLF Electronic Resource Management Initiative, especially Appendix E (Data
Element Dictionary) and Appendix F (Data Structure). The ERD presents a visual
representation of e-resource management concepts and the relationships between them.
The Data Element Dictionary identifies and defines the individual data elements that an
e-resource management system must contain and manage, but leaves the relationship
between the elements to be inferred by the reader. The Data Structure associates each
data element with the entities and relationships defined in the ERD. Together, these
three documents form a complete conceptual data model for e-resource management.
Understanding the Model
There are several different modeling systems for entity relationship diagramming. This ERD
is presented in the Information Engineering style. Those unfamiliar with entity relationship
diagramming or unfamiliar with this style of notation may wish to consult the following
section to clarify the diagramming symbology.

Entities
Entities are concepts within the data model. Each entity is represented by a box within the
ERD. Entities are abstract concepts, each representing one or more instances of the concept
in question. An entity might be considered a container that holds all of the instances of a
particular thing in a system. Entities are equivalent to database tables in a relational database,
with each row of the table representing an instance of that entity.
Remember that each entity represents a container for instances of the thing in question. The
diagram below has an entity for student and another for school. This indicates that the
system being modeled may contain one or more students and one or more schools.
30

`
S
T
U
D
E
N
T

S
C
H
O
O
L

So far, no relationship between students and schools has been indicated.

Relationships
Relationships are represented by lines between entities. Relationship lines indicate that each
instance of an entity may have a relationship with instances of the connected entity, and vice
versa.
S
T
U
D
E
N
T

S
C
H
O
O
L

The diagram above now indicates that students may have some relationship with schools.
More specifically, there may be a relationship between a particular student (an instance of the
student entity) and a particular school (an instance of the school entity).
If necessary, a relationship line may be labeled to define the relationship. In this case, one
can infer that a student may attend a school, or that a school may enroll students. But if
necessary, this relationship could be labeled for clarification:
STUDENT

attends/
enrolls

SCHOOL

Read the first relationship definition, attends, when tracing the relationship left to right or
top to bottom. Read the second definition enrolls, when tracing the relationship right to left
or bottom to top.

Optionality and Cardinality


Symbols at the ends of the relationship lines indicate the optionality and the cardinality of
each relationship. Optionality expresses whether the relationship is optional or mandatory.
Cardinality expresses the maximum number of relationships.
As a relationship line is followed from an entity to another, near the related entity two
symbols will appear. The first of those is the optionality indicator. A circle ( ) indicates
that the relationship is optionalthe minimum number of relationships between each
instance of the first entity and instances of the related entity is zero. One can think of the
circle as a zero, or a letter O for optional. A stroke ( | ) indicates that the relationship is
mandatorythe minimum number of relationships between each instance of the first entity
and instances of the related entity is one.
The second symbol indicates cardinality. A stroke ( | ) indicates that the maximum number of
relationships is one. A crows-foot ( ) indicates that many such relationships between
instances of the related entities might exist.

31

`
The following diagram indicates all of the possible combinations:

E
a
c
hin
s
ta
n
c
eo
fA
isre
la
te
dtoam
in
im
u
m
o
f
z
e
roa
n
dam
a
x
im
u
m
o
fo
n
ein
s
ta
n
c
eo
fB

E
a
c
hin
s
ta
n
c
eo
fB
isre
la
te
dtoam
in
im
u
m
o
f
o
n
ea
n
dam
a
x
im
u
m
o
fo
n
ein
s
ta
n
c
eo
fA

E
a
c
hin
s
ta
n
c
eo
fA
isre
la
te
dtoam
in
im
u
m
o
f
o
n
ea
n
dam
a
x
im
u
m
o
fm
a
n
yin
s
ta
n
c
e
so
fB

E
a
c
hin
s
ta
n
c
eo
fB
isre
la
te
dtoam
in
im
u
m
o
f
z
e
roa
n
dam
a
x
im
u
m
o
fm
a
n
yin
s
ta
n
c
e
so
fA

In our model, we wish to indicate that each school may enroll many students, or may not
enroll any students at all. We also wish to indicate that each student attends exactly one
school. The following diagram indicates this optionality and cardinality:

E
a
c
h
s
c
h
o
o
le
n
r
o
lls

S
T
U
D
E
N
T

E
a
c
h
s
tu
d
e
n
ta
tte
n
d
s

a
tle
a
s
tz
e
r
o

a
tle
a
s
to
n
e

a
n
d
a
tm
o
s
tm
a
n
y

a
n
d
a
tm
o
s
to
n
e

s
tu
d
e
n
ts

S
C
H
O
O
L

s
c
h
o
o
l

It is important to note that relationship optionality and cardinality constraints apply


specifically to the system being modeled, not to all possible systems. According to the
example modeled above, a school might not enroll any studentsthat relationship is optional.
A school without students is not much of a school, and indeed if the system being modeled
were a school system enrollment database, the relationship would probably be mandatory.
However, if the system being modeled is an extracurricular honors program, there may be
schools that have no students currently participating in the program. Consider the function of
the system and consult the other documents in the data model to clarify modeling decisions.

Bridge Entities
When an instance of an entity may be related to multiple instances of another entity and vice
versa, that is called a many-to-many relationship. In the example below, a supplier may
provide many different products, and each type of product may be offered by many suppliers:
S
U
P
P
L
I
E
R

p
r
o
v
id
e
s
/
o
f
f
e
r
e
d
b
y

P
R
O
D
U
C
T

32

`
While this relationship model is perfectly valid, it cannot be translated directly into a
relational database design. In a relational database, relationships are expressed by keys in a
table column that point to the correct instance in the related table. A many-to-many
relationship does not allow this relationship expression, because each record in each table
might have to point to multiple records in the other table.
In order to build a relational database that captures this relationship, it is necessary to build a
bridge between the two entities that uniquely expresses each relationship instance. This can
be modeled in an ERD with a bridge entity, an entity box containing a diamond, which may
replace the many-to-many relationship. (The diamond is used in other ER modeling systems
to indicate relationships, or may be viewed as the joiningthe bridgeof the many-to-many
crows-feet).
S
U
P
P
L
I
E
R

P
R
O
V
I
D
E
S
/
O
F
F
E
R
E
D
B
Y

P
R
O
D
U
C
T

This diagram expresses the same relationship as the diagram above. Each instance of the
provides bridge entity indicates that a certain supplier can provide a certain product.
In addition to explicitly depicting a relational database structure that can capture a many-tomany relationship, the bridge entity has an additional function in abstract entity-relationship
modeling: A bridge entity may capture attributes that are specific to the relationship between
instances of the bridged entities. In the supplier and product example, a product does not
have an inherent cost; it only has a cost in relation to the supplier who sells it. Similarly, a
supplier may not have a uniform delivery time; delivery times may vary in relation to the
product being delivered. Any attributes that are dependent on the relationship would be
associated with the relationships bridge entity.

Recursive Relationships
Instances of entities may have relationships with other instances of the same entity. These
relationships may be drawn with relationship lines that begin and end connected to the same
entity. Common occurrences of these recursive relationships include parent/child
relationships:
PERSON

father of/
child of

The diagram above indicates that a person may be the father of zero or many persons, and
that a person may have zero or one father. (Not every persons father will be recorded in the
system, so the relationship is modeled as optional).

33

Multiple Relationships between Entities


An entity may have multiple relationships with another entity. These are depicted in the ERD
with multiple relationship lines connecting the two entities
s
a
le
s
p
e
rs
o
n

E
M
P
L
O
Y
E
E

C
L
IE
N
T

c
u
s
to
m
e
rs
e
rv
ic
ere
p

The diagram above indicates that an employee may be the salesperson assigned to zero or
many clients, and an employee may be the customer service representative for zero or many
clients. Each client has exactly one salesperson and exactly one customer service
representative. Each clients salesperson may or may not be the same employee as the
clients customer service representative; each relationship is treated independently.

Entity Subtypes
There are times when it is convenient to depict relationships that apply to an entire class of
things, as well as depict relationships that apply only to certain types of the larger class.
Entity subtypes accommodate these relationship depictions. In the ERD, entity subtypes may
be depicted by entity boxes shown within larger entity boxes. The large entity represents the
class, and the smaller boxes depict the subtypes.
INVENTORY
VEHICLE

PART

MODEL

MFG.
LOCATION

The example above depicts an inventory entity, with the subtypes of vehicle and part.
A vehicle has one or many parts, and every part is associated with one and only one kind of
vehicle (according to this diagram, there are no interchangeable components). All items in
inventory, whether they are vehicles or parts, have a manufacturing location, but only
vehicles are of a particular model.

34

Exclusive-Or Relationship
If an entity instance may have either one relationship or another, but not both, the constraint
may be modeled with an exclusive-or relationship, represented as a tree with a solid dot
where the tree branches. The following diagram indicates that each convict is assigned to a
prison, or to a parole officer, but not both:
P
R
IS
O
N

C
O
N
V
IC
T
P
A
R
O
L
E
O
F
F
IC
E
R

CONCLUSION

This entity-relationship diagram depicts the major concepts and relationships needed for
managing electronic resources. It is neither a complete data model depicting every necessary
relational database table, nor is it meant to be a proscriptive design for implementations of
electronic resource management systems. Alternate models may capture the necessary
attributes and relationships. Hopefully this document, along with the other components of
the Report of the DLF Electronic Resource Management Initiative will assist developers with
envisioning the complexity of the environment that an ERM system must address, and ensure
that crucial relationships and features will be included in ERM products.

35

`
NORMALIZATION
Normalization is a method for organizing data elements in a database into tables.
Normalization Avoids
Duplication of Data The same data is listed in multiple lines of the database
Insert Anomaly A record about an entity cannot be inserted into the table without
first inserting information about another entity Cannot enter a customer without a
sales order
Delete Anomaly A record cannot be deleted without deleting a record about a
related entity. Cannot delete a sales order without deleting all of the customers
information.
Update Anomaly Cannot update information without changing information in many
places. To update customer information, it must be updated for each sales order the
customer has placed
Normalization is a three stage process After the first stage, the data is said to be in first
normal form, after the second, it is in second normal form, after the third, it is in third normal
form
Before Normalization
1. Begin with a list of all of the fields that must appear in the database. Think of this as one
big table.
2. Do not include computed fields
3. One place to begin getting this information is from a printed document used by the
system.
4. Additional attributes besides those for the entities described on the document can be
added to the database.
Before Normalization Example
See Sales Order from below:

36

`
Sales Order
Fiction Company
202 N. Main
Mahattan, KS 66502
CustomerNumber:
Customer Name:
Customer Address:

Item Ordered
800
801
805

1001
ABC Company
100 Points
Manhattan, KS 66502

Description
widgit small
tingimajigger
thingibob

Sales Order Number:


405
Sales Order Date:
2/1/2000
Clerk Number:
210
Clerk Name:
Martin Lawrence

Quantity Unit Price Total


40
60.00 2,400.00
20
20.00
400.00
10
100.00 1,000.00

Order Total

3,800.00

Fields in the original data table will be as follows:


SalesOrderNo, Date, CustomerNo, CustomerName, CustomerAdd, ClerkNo,
ClerkName, ItemNo, Description, Qty, UnitPrice
Think of this as the baseline one large table
Normalization: First Normal Form

Separate Repeating Groups into New Tables.


Repeating Groups Fields that may be repeated several times for one document/entity
Create a new table containing the repeating data
The primary key of the new table (repeating group) is always a composite key;
Usually document number and a field uniquely describing the repeating line, like an
item number.

First Normal Form Example


The new table is as follows:
SalesOrderNo, ItemNo, Description, Qty, UnitPrice
The repeating fields will be removed from the original data table, leaving the following.
SalesOrderNo, Date, CustomerNo, CustomerName, CustomerAdd, ClerkNo,
ClerkName
These two tables are a database in first normal form
What if we did not Normalize the Database to First Normal Form?
Repetition of Data SO Header data repeated for every line in sales order.
Normalization: Second Normal Form

Remove Partial Dependencies.


Functional Dependency The value of one attribute in a table is determined entirely
by the value of another.

37

Partial Dependency A type of functional dependency where an attribute is


functionally dependent on only part of the primary key (primary key must be a
composite key).
Create separate table with the functionally dependent data and the part of the key on
which it depends. Tables created at this step will usually contain descriptions of
resources.

Second Normal Form Example


The new table will contain the following fields:
ItemNo, Description
All of these fields except the primary key will be removed from the original table. The
primary key will be left in the original table to allow linking of data:
SalesOrderNo, ItemNo, Qty, UnitPrice
Never treat price as dependent on item. Price may be different for different sales orders
(discounts, special customers, etc.)
Along with the unchanged table below, these tables make up a database in second normal
form:
SalesOrderNo, Date, CustomerNo, CustomerName, CustomerAdd, ClerkNo,
ClerkName
What if we did not Normalize the Database to Second Normal Form?
Repetition of Data Description would appear every time we had an order for the
item
Delete Anomalies All information about inventory items is stored in the
SalesOrderDetail table. Delete a sales order, delete the item.
Insert Anomalies To insert an inventory item, must insert sales order.
Update Anomalies To change the description, must change it on every SO.
Normalization: Third Normal Form

Remove transitive dependencies.


Transitive Dependency A type of functional dependency where an attribute is
functionally dependent on an attribute other than the primary key. Thus its value is
only indirectly determined by the primary key.
Create a separate table containing the attribute and the fields that are functionally
dependent on it. Tables created at this step will usually contain descriptions of either
resources or agents. Keep a copy of the key attribute in the original file.
Third Normal Form Example
The new tables would be:
CustomerNo, CustomerName, CustomerAdd
ClerkNo, ClerkName
All of these fields except the primary key will be removed from the original table. The
primary key will be left in the original table to allow linking of data as follows:
SalesOrderNo, Date, CustomerNo, ClerkNo
Together with the unchanged tables below, these tables make up the database in third normal
form.
ItemNo, Description
SalesOrderNo, ItemNo, Qty, UnitPrice
What if we did not Normalize the Database to Third Normal Form?
38

`
Repetition of Data Detail for Cust/Clerk would appear on every SO
Delete Anomalies Delete a sales order, delete the customer/clerk
Insert Anomalies To insert a customer/clerk, must insert sales order.
Update Anomalies To change the name/address, etc, must change it on every SO.
Completed Tables in Third Normal Form
Customers: CustomerNo, CustomerName, CustomerAdd
Clerks: ClerkNo, ClerkName
Inventory Items: ItemNo, Description
Sales Orders: SalesOrderNo, Date, CustomerNo, ClerkNo
SalesOrderDetail: SalesOrderNo, ItemNo, Qty, UnitPrice

RESULT
Thus ER diagrams and Normalization have been studied in detail.

39

Ex.no:8
DESIGN AND IMPLEMENTATION OF PAYROLL PROCESSING
SYSTEM
AIM
To design and implement the payroll processing system.

CODES
Private Sub Command2_Click()
d1.Recordset.MoveFirst
End Sub
Private Sub Command3_Click()
If d1.Recordset.BOF = True Then
MsgBox ("BEGINING OF FILE")
d1.Recordset.MoveLast
Else
d1.Recordset.MovePrevious
End If
End Sub
Private Sub Command4_Click()
If d1.Recordset.EOF = True Then
MsgBox ("END OF FILE")
d1.Recordset.MoveFirst
Else
d1.Recordset.MoveNext
End If
End Sub
Private Sub Command5_Click()
d1.Recordset.MoveLast
End Sub
Private Sub Command6_Click()
d1.Recordset.Edit
d1.Recordset.AddNew
End Sub

Private Sub Command7_Click()


d1.Recordset.Edit
d1.Recordset.Update
End Sub

40

`
Private Sub Command8_Click()
d1.Recordset.Edit
d1.Recordset.Delete
End Sub

SCREENSHOTS

RESULT
Thus payroll processing has been executed successfully.
41

Ex.no:9
DESIGN AND IMPLEMENTATION OF BANKING SYSTEM
AIM
To design and implement BANKING system.

CODES
Private Sub Command2_Click()
d1.Recordset.MoveFirst
End Sub
Private Sub Command3_Click()
If d1.Recordset.BOF = True Then
MsgBox ("BEGINING OF FILE")
d1.Recordset.MoveLast
Else
d1.Recordset.MovePrevious
End If
End Sub
Private Sub Command4_Click()
If d1.Recordset.EOF = True Then
MsgBox ("END OF FILE")
d1.Recordset.MoveFirst
Else
d1.Recordset.MoveNext
End If
End Sub
Private Sub Command5_Click()
d1.Recordset.MoveLast
End Sub
Private Sub Command6_Click()
d1.Recordset.Edit
d1.Recordset.AddNew
End Sub

Private Sub Command7_Click()


d1.Recordset.Edit
d1.Recordset.Update
End Sub

42

`
Private Sub Command8_Click()
d1.Recordset.Edit
d1.Recordset.Delete
End Sub

SCREENSHOTS

RESULT
Thus banking system has been executed successfully.
43

Ex.no:10
DESIGN AND IMPLEMENTATION OF LIBRARY INFORMATION
SYSTEM
AIM
To design and implement LIBRARY INFORMATION system.

CODES
Private Sub Command2_Click()
d1.Recordset.MoveFirst
End Sub
Private Sub Command3_Click()
If d1.Recordset.BOF = True Then
MsgBox ("BEGINING OF FILE")
d1.Recordset.MoveLast
Else
d1.Recordset.MovePrevious
End If
End Sub
Private Sub Command4_Click()
If d1.Recordset.EOF = True Then
MsgBox ("END OF FILE")
d1.Recordset.MoveFirst
Else
d1.Recordset.MoveNext
End If
End Sub
Private Sub Command5_Click()
d1.Recordset.MoveLast
End Sub
Private Sub Command6_Click()
d1.Recordset.Edit
d1.Recordset.AddNew
End Sub
Private Sub Command7_Click()
d1.Recordset.Edit
d1.Recordset.Update
End Sub
Private Sub Command8_Click()
d1.Recordset.Edit
44

`
d1.Recordset.Delete
End Sub

SCREENSHOTS

RESULT
Thus library information has been executed successfully.
45

Ex. No.11
DESIGN AND IMPLEMENTATION OF STUDENT INFORMATION
SYSTEM
AIM
To design and implement STUDENT INFORMATION system.

CODES
Private Sub Command2_Click()
d1.Recordset.MoveFirst
End Sub
Private Sub Command3_Click()
If d1.Recordset.BOF = True Then
MsgBox ("BEGINING OF FILE")
d1.Recordset.MoveLast
Else
d1.Recordset.MovePrevious
End If
End Sub
Private Sub Command4_Click()
If d1.Recordset.EOF = True Then
MsgBox ("END OF FILE")
d1.Recordset.MoveFirst
Else
d1.Recordset.MoveNext
End If
End Sub
Private Sub Command5_Click()
d1.Recordset.MoveLast
End Sub
Private Sub Command6_Click()
d1.Recordset.Edit
d1.Recordset.AddNew
End Sub
Private Sub Command7_Click()
d1.Recordset.Edit
d1.Recordset.Update
End Sub

46

`
Private Sub Command8_Click()
d1.Recordset.Edit
d1.Recordset.Delete
End Sub

SCREENSHOTS

RESULT
Thus student information has been executed successfully.

47

Ex. No.12
AUTOMATIC BACKUP OF FILES AND RECOVERY OF FILES
AIM
To study about automatic backup of files and recovery of files.

User-Managed Flashback Features of Oracle


Oracle's flashback features, which let you undo damage to your database after logical data
corruption, include the following:

Oracle Flashback Database, which returns your entire database to a previous state
without requiring you to restore files from backup;
Oracle Flashback Table, which returns one or more tables to their contents at a
previous time;
Oracle Flashback Drop, which undoes the effects of the DROP TABLE operation;
Oracle Flashback Query, which is used to query the contents of the database at a past
time;
Oracle Flashback Version Query, which lets you view past states of data;
Oracle Flashback Transaction Query, which is used to review transactions affecting a
table over time.

All of these operations are available within SQL*Plus, and none of them require the use of
Recovery Manager.

Performing Flashback Database with SQL*Plus


The SQL*Plus FLASHBACK DATABASE command performs the same function as the
RMAN FLASHBACK DATABASE command: it returns the database to a prior state.
Note that using Flashback Database requires that you create a flash recovery area for your
database and enable the collection of flashback logs. See Oracle Database Backup and
Recovery Basics for more details about how the Flashback Database feature works,
requirements for using Flashback Database, and how to enable collection of flashback logs
required for Flashback Database. The requirements and preparations are the same whether
you use RMAN or user-managed backup and recovery.
To perform the FLASHBACK DATABASE operation in SQL*Plus:
Query the target database to determine the range of possible flashback SCNs. The
following SQL*Plus queries show you the latest and earliest SCN in the flashback
window:
48

`
SQL> SELECT CURRENT_SCN FROM V$DATABASE;
SQL> SELECT OLDEST_FLASHBACK_SCN, OLDEST_FLASHBACK_TIME
FROM V$FLASHBACK_DATABASE_LOG;
Use other flashback features if necessary, to identify the SCN or time of the unwanted
changes to your database.
Start SQL*Plus with administrator privileges, and run the FLASHBACK
DATABASE statement to return the database to a prior TIMESTAMP or SCN. For
example:
FLASHBACK DATABASE TO SCN 46963;
FLASHBACK DATABASE TO TIMESTAMP (SYSDATE-1/24);
FLASHBACK DATABASE TO TIMESTAMP timestamp'2002-11-05 14:00:00';
FLASHBACK DATABASE
TO TIMESTAMP to_timestamp('2002-11-11 16:00:00', 'YYYY-MM-DD
HH24:MI:SS');
Open the database read-only to examine the results of the Flashback Database
operation. When the operation completes, you can open the database read-only and
perform some queries to make sure you have recovered the data you need. If you find
that you need to perform Flashback Database again to a different target time, then
use RECOVER DATABASE to return the database back to the present time, and then
try anotherFLASHBACK DATABASE statement.
If you are satisfied with the results of Flashback Database, then you can re-open your
database with the RESETLOGS option. If appropriate, you can also use an Oracle
export utility like Data Pump Export to save lost data, use RECOVER
DATABASE to return the database to the present, and re-import the lost object.
Determining Which Datafiles Require Recovery
You can use the dynamic performance view V$RECOVER_FILE to determine which files to
restore in preparation for media recovery. This view lists all files that need to be recovered
and explains why they need to be recovered.
If you are planning to perform complete recovery rather than point-in-time recovery,
you can recover only those datafiles which require recovery, rather than the whole
database. (Note that for point-in-time recovery, you must restore and recover all
datafiles, unless you perform tablespace point-in-time recovery as described
inChapter 20, "Performing User-Managed TSPITR". You can also use Flashback
Database as described in"User-Managed Flashback Features of Oracle", but this
affects all datafiles and returns the entire database to a past time.)
You can query V$RECOVER_FILE to list datafiles requiring recovery by datafile
number with their status and error information.
SELECT FILE#, ERROR, ONLINE_STATUS, CHANGE#, TIME
49

`
FROM V$RECOVER_FILE;
You can also perform useful joins using the datafile number and
the V$DATAFILE and V$TABLESPACE views, to get the datafile and tablespace
names. Use the following SQL*Plus commands to format the output of the query:
COL DF# FORMAT 999
COL DF_NAME FORMAT A35
COL TBSP_NAME FORMAT A7
COL STATUS FORMAT A7
COL ERROR FORMAT A10
COL CHANGE# FORMAT 99999999
SELECT r.FILE# AS df#, d.NAME AS df_name, t.NAME AS tbsp_name,
d.STATUS, r.ERROR, r.CHANGE#, r.TIME
FROM V$RECOVER_FILE r, V$DATAFILE d, V$TABLESPACE t
WHERE t.TS# = d.TS#
AND d.FILE# = r.FILE#
;

RESULT
Thus the automatic recovery if files and backup of files are studied.

50

You might also like