You are on page 1of 56

KPR INSTITUTE OF ENGINEERING AND TECHNOLOGY

COIMBATORE – 641 407

CS6312 – DATABASE MANAGEMENT SYSTEMS


LABORATORY

RECORD NOTEBOOK
KPR INSTITUTE OF ENGINEERING AND TECHNOLGY
COIMBATORE – 641 407

§
LABORATORY RECORD
Name : ……………………………………………………………….

Roll Number : ……………………………………………………………….

Subject Code & Title: ……………………………………………………………….

Department : ……………………………………………………………….

Year & Semester : ……………………………………………………………….

This is the certified record of work done by………………………………………….

Register Number………………………………………………………

Staff In- Charge Head of the Department

Place:

Date:

He/She has submitted the record for the University Practical Examination held on

……………………

Internal Examiner External Examiner


INDEX

PAGE
S.NO Date NAME OF THE EXERCISE Marks Sign
NO.

1 DDL- Data Definition, Table Creation, Constraints.

DML- Insert, Select Commands, Update & Delete


2
Commands.

3 TCL –Rollback, Commit commands.

4 Writing and Practice of Simple Queries.

5 Nested Queries & Queries Using Group By And Other Clauses.

6 Problems Based On Views, Synonym, Sequence & Index.

7 Creating Database.

High Level Programming Language Extension (PL/SQL


8
Blocks).

9 PL/SQL Procedures.

10 PL/SQL Functions.

11 Triggers

12 Database Design and implementation (Mini Project).

1
1. DDL COMMANDS

AIM:

To create, alter, truncate and drop a table using DDL commands.

DDL COMMANDS:

OVERVIEW:
CREATE - to create objects in the database
ALTER - alters the structure of the objects in the database
DROP - delete objects from the database
TRUNCATE - remove all records from a table, including all spaces allocated for the records are
removed
COMMENT - add comments to the data dictionary
GRANT - gives user's access privileges to database
REVOKE - withdraw access privileges given with the GRANT command

SQL - CREATE TABLE

Syntax: CREATE TABLE tablename (column_name data_ type constraints, …)

Example:

INPUT::

SQL> CREATE TABLE DEPARTMENT ( DEPTID VARCHAR(5) CONSTRAINT PKEY PRIMARY KEY,

DEPTNAME VARCHAR(15), DOS DATE CONSTRAINT NOTNULL );

OUTPUT: Table created.

SQL> CREATE TABLE EMPLOYE ( EMPID VARCHAR(5) CONSTRAINT PKEY PRIMARY KEY,

EMPNAME VARCHAR(15), JOB CHAR(10) CONSTRAINT UNIQ1 UNIQUE,

MGRID VARCHAR(5) CONSTRAINT FKEY1 REFERENCES EMP (EMPID),

HIREDATE DATE, DEPTID VARCHAR(5) CONSTRAINT FKEY2 REFERENCES DEPT(DEPTID),

SALARY NUMBER(7,2));

OUTPUT: Table created.

SQL - DESC TABLE

2
SQL>desc Employe;

Name Null? Type

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

EMPID NOT NULL VARCHAR2(5)

EMPNAME VARCHAR2(20)

JOB NOT NULL CHAR(10)

MGRID NOT NULL VARCHAR2(5)

HIREDATE DATE

DEPTID VARCHAR2(5)

SALARY NUMBER(7,2)

SQL - ALTER TABLE

INPUT::

SQL>ALTER TABLE EMPLOYE ADD CONSTRAINT NTNLL NOT NULL (SALARY);

OUTPUT: Table Altered.

Similarly, ALTER TABLE EMPLOYE DROP CONSTRAINT UNIQ1;

SQL - DROP TABLE

– Deletes table structure – Cannot be recovered – Use with caution

INPUT::

SQL> DROP TABLE EMP; Here EMP is table name

OUTPUT: Table Dropped.

SQL - TRUNCATE TABLE

TRUNCATE TRUNCATE TABLE <TABLE NAME>;

RESULT:

Thus the table was successfully created, altered, truncated, and dropped.

3
2. DML COMMANDS

AIM:

To insert, select, update and delete records in a table using DML commands.

DML COMMANDS:

COMMANDS OVERVIEW:
SELECT - retrieve data from the a database
INSERT - insert data into a table
UPDATE - updates existing data within a table
DELETE - deletes all records from a table, the space for the records remain

SQL – SELECT FROM

Selecting all records from a table

SELECT * FROM EMPLOYE

Listing the selected records which satisfies the given condition from a table

SELECT * FROM EMPLOYE WHERE DEPTID=’DPT01’

SQL - INSERT INTO

Syntax: INSERT INTO tablename VALUES (value list)

Single-row insert

INSERT INTO DEPARTMENT VALUES (‘DPT02’,’TESTING’,’10-JAN-2012’)

Inserting one row, with values to the column in the given order

INSERT INTO DEPARTMENT (DEPTNAME, DEPTID) VALUES (‘DESIGN’, ‘DPT02’);

Inserting one or more rows with values from other tables.

INSERT INTO DEPARTMENT (DEPTID, DEPTNAME)

SELECT EMPID, EMPNAME FROM EMP WHERE MGRID=EMPID;

OTHER EXAMPLES:

INPUT::

SQL>INSERT INTO EMPLOYE VALUES (‘Emp121’,’Gayle’,’Testing’,’Emp01’,’01-Feb-2013’, ’Dpt01’, 32000);

OUTPUT: 1 row created.

4
INPUT::

SQL>INSERT INTO DEPARTMENT VALUES(‘&deptid,’&deptname’);

Enter value for deptid: Dpt01

Enter value for deptname: Development

OUTPUT:

old 1: Insert into department values(‘&deptid,’&deptname’)

new 1: Insert into department values(‘Dpt01’,' Development’)

1 row created.

SQL - UPDATE

Syntax: UPDATE tablename SET COLUMN_NAME =value [ WHERE CONDITION]

INPUT::

SQL> UPDATE DEPT SET DOS=’01-JAN-2010’ WHERE DEPTID=’DPT01’;

1 row updated.

SQL - DELETE FROM

Syntax: DELETE FROM tablename WHERE condition

INPUT::

SQL> DELETE FROM DEPARTMENT;

OUTPUT: 1 row deleted.

RESULT:

Thus the table was successfully inserted, updated, select, and deleted.

5
3. TCL COMMANDS

AIM:

To create save point, commit and rollback while using a transaction.

TCL COMMANDS:

COMMANDS OVERVIEW

COMMIT - save work done & it is visible to other users.


SAVEPOINT - identify a point in a transaction to which you can later roll back
ROLLBACK - restore database to original since the last COMMIT
SET TRANSACTION - Change transaction options like what rollback segment to use

SAVEPOINT
Syntax: savepoint username;
INPUT::
SQL> savepoint emp;
Output:
savepoint created;

COMMIT
Syntax: commit;
INPUT::
SQL> commit;
Output:
Commit complete.

ROLLBACK
Syntax:
rollback to savepoint_text_identifier;
INPUT::
SQL> rollback to emp;
Output:
Rollback complete.

RESULT:

Thus the table was successfully saved, committed and rollback.

6
4. WRITING AND PRACTICE OF SIMPLE QUERIES

AIM:

To write simple SQL queries and to practice them.

PROBLEM STATEMENTS:

1. Get the description of EMP table.

SQL> DESC EMP;

OUTPUT:
Name Null? Type
-------------------------------- ----------------------- -------------------------
EMPNO NOT NULL NUMBER(4)
ENAME VARCHAR2(10)
JOB VARCHAR2(9)
MGR NUMBER(4)
HIREDATE DATE
SAL NUMBER(7,2)
COMM NUMBER(7,2)
DEPTNO NUMBER(3)
AGE NUMBER(3)
ESAL NUMBER(10)

2.List all employee details.

SQL>SELECT * FROM EMP;

OUTPUT:
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO AGE ESAL
-------- ---------- --------- ---------- --------- ---------- ---------- ---------- ---------- -----------------
7369 SMITH CLERK 7902 17-DEC-10 8000 0 20 25 0
7499 ALLEN SALESMAN 7698 20-FEB-11 16000 300 30 25 0
7521 WARD SALESMAN 7698 22-FEB-11 12500 500 30 25 0
7566 JONES MANAGER 7839 02-APR-11 29705 500 20 25 0
7698 BLAKE MANAGER 7839 01-MAY-12 28500 1400 30 25 0

3. List all employee names and their salaries, whose salary lies between 1500/- and 3500/- both inclusive.

INPUT:
SQL>SELECT ENAME FROM EMP WHERE SAL BETWEEN 1500 AND 3500;

OUTPUT:
ENAME
----------
ALLEN
JONES
BLAKE
CLARK

4 rows selected.

7
4. List all employee names and their and their manager whose manager is 7902 or 7566 0r 7789.

INPUT: SQL> SELECT ENAME FROM EMP WHERE MGR IN(7602,7566,7789);

OUTPUT:

ENAME
-------
SCOTT
FORD

5. List all employees which starts with either J or T.

INPUT: SQL> SELECT ENAME FROM EMP WHERE ENAME LIKE ‘J%’ OR ENAME LIKE ‘T%’;

OUTPUT:

ENAME
---------
JONES
TURNER
JAMES

6. List all employee names and jobs, whose job title includes M or P.

INPUT: SQL> SELECT ENAME,JOB FROM EMP WHERE JOB LIKE ‘M%’ OR JOB LIKE ‘P%’;

OUTPUT:
ENAME JOB
---------- ---------
JONES MANAGER
BLAKE MANAGER
CLARK MANAGER
KING PRESIDENT

7. List all jobs available in employee table.

INPUT: SQL> SELECT DISTINCT JOB FROM EMP;

OUTPUT:
JOB
---------
ANALYST
CLERK
MANAGER
PRESIDENT
SALESMAN
assistant
clerk

7 rows selected.

8. List all employees who belongs to the department 10 or 20.

INPUT: SQL> SELECT ENAME FROM EMP WHERE DEPTNO IN (10,20);

8
OUTPUT:
ENAME
----------
SMITH
JONES
CLARK
SCOTT
KING
ADAMS
FORD
MILLER

8 rows selected.

9. List all employee names , salary and 15% rise in salary.

INPUT: SQL> SELECT ENAME , SAL , SAL+0.15* SAL FROM EMP;

RESULT:
ENAME SAL SAL+0.15*SAL
---------- ---------- ------------
SMITH 800 920
ALLEN 1600 1840
WARD 1250 1437.5
JONES 2975 3421.25
MARTIN 1250 1437.5
BLAKE 2850 3277.5
CLARK 2450 2817.5
7 rows selected.

10. List minimum, maximum, average salaries of employee.

INPUT: SQL> SELECT MIN(SAL),MAX(SAL),AVG(SAL) FROM EMP;

OUTPUT:

MIN(SAL) MAX(SAL) AVG(SAL)


--------- ---------- ----------
3 5000 1936.94118

11. Find how many job titles are available in employee table.

INPUT: SQL> SELECT COUNT (DISTINCT JOB) FROM EMP;

OUTPUT:
COUNT(DISTINCTJOB)
------------------
7
12. What is the difference between maximum and minimum salaries of employees in the organization?

INPUT: SQL> SELECT MAX(SAL)-MIN(SAL) FROM EMP;

OUTPUT:
MAX(SAL)-MIN(SAL)

9
-----------------
4997

13. Display all employee names and salary whose salary is greater than minimum salary of the company
and job title starts with ‘M’.

INPUT: SQL> SELECT ENAME,SAL FROM EMP WHERE JOB LIKE ‘M%’ AND SAL >

(SELECT MIN (SAL) FROM EMP);

OUTPUT:
ENAME SAL
---------- ----------
JONES 2975
BLAKE 2850
CLARK 2450

14. Find how much amount the company is spending towards salaries.

INPUT: SQL> SELECT SUM (SAL) FROM EMP;

OUTPUT:
SUM(SAL)
---------
32928

15. Display name of the dept. with deptno 20.

INPUT: SQL>SELECT ENAME FROM EMP WHERE DEPTNO = 20;

OUTPUT :
ENAME
----------
SMITH
JONES
SCOTT
ADAMS

16. List ename whose commission is NULL.

INPUT: SQL> SELECT ENAME FROM EMP WHERE COMM IS NULL;

OUTPUT:

ENAME
------------
CLARK
SCOTT
KING
ADAMS
JAMES
FORD
6 rows selected.

10
17. Find no.of dept in employee table.

INPUT: SQL> SELECT COUNT (DISTINCT ENAME) FROM EMP;

OUTPUT:

COUNT(DISTINCT ENAME)

---------------------------------------
17
18. List ename whose manager is not NULL.

INPUT: SQL> SELECT ENAME FROM EMP WHERE MGR IS NOT NULL;

OUTPUT:
ENAME
----------
SMITH
ALLEN
WARD
JONES
MARTIN
5 rows selected.

19. Calculate the experience in years of each programmer and display along with their name in
descending order.

INPUT: SQL> SELECT PNAME, ROUND (MONTHS_BETWEEN(SYSDATE, DOJ)/12, 2) "EXPERIENCE" FROM


PROGRAMMER ORDER BY MONTHS_BETWEEN (SYSDATE, DOJ) DESC;

20 . In which month most number of programmers has joined.


INPUT: SQL>SELECT TO_CHAR (DOJ,’YY’) FROM PROGRAMMER GROUP BY TO_CHAR (DOJ,’YY’) HAVING
COUNT (*) = (SELECT MAX (COUNT(*)) FROM PROGRAMMER GROUP BY TO_CHAR (DOJ,’YY’);

RESULT:

Thus the given problem statements were solved using simple queries.

11
5. NESTED QUERIES & QUERIES USING GROUP BY AND OTHER CLAUSES

AIM:

To write queries using Set operations, to write nested queries and also to write queries using
clauses such as GROUP BY, ORDER BY, etc. and retrieving information by joining tables.

SET OPERATIONS & OTHER CLAUSES:


NESTED QUERY: - A nested query makes use of another sub-query to compute or retrieve
the information.
UNION - OR
INTERSECT - AND
EXCEPT - NOT
Order by : The order by clause is used to display the results in sorted order.
Group by : The attribute or attributes given in the clauses are used to form groups. Tuples with the
same value on all attributes in the group by clause are placed in one group.
Having: SQL applies predicates (conditions) in the having clause after groups have been formed, so
aggregate function be used.

PROBLEM STATEMENTS:

Consider the relations

Programmer(pname, deptname,doj,job,gender,salary,mgrid)

Study(pname, institute,city)

Software(title,dname,dlan,dcost,scost)

1. Find the name of the institute in which the person studied and developed the costliest package.

INPUT: SQL> SELECT SPLACE, PNAME FROM STUDY WHERE PNAME = (SELECT PNAME FROM SOFTWARE

WHERE SCOST = (SELECT MAX (SCOST) FROM SOFTWARE);

OUTPUT:
SPLACE PNAME
------------ -------------
SAHBHARI MARY

2. Find the salary and institute of a person who developed the highest selling package.

INPUT: SQL> SELECT STUDY.PNAME, SAL, SPLACE FROM STUDY, PROGRAMMER WHERE

STUDY.PNAME = PROGRAMMER.PNAME AND STUDY.PNAME = (SELECT PNAME FROM SOFTWARE WHERE

12
SCOST = (SELECT MAX (SCOST) FROM SOFTWARE));

OUTPUT:

PNAME SAL SPLACE


----------- ------ -----------
MARY 4500 S ABHARI

3. How many packages were developed by the person who developed the cheapest package.

INPUT: SQL> SELECT PNAME, COUNT (TITLE) FROM SOFTWARE WHERE DCOST = (SELECT MIN(DCOST)
FROM SOFTWARE) GROUP BY PNAME;

RESULT
PNAME COUNT(TITLE)
------------- ----------------------
VIJAY 1

4. Calculate the amount to be recovered for those packages whose development cost has not yet
recovered.

INPUT: SQL>SELECT TITLE, (DCOST-SCOST) FROM SOFTWARE WHERE DCOST > SCOST;

5. Display the title, scost, dcost, difference of scost and dcost in the descending order of difference.

INPUT: SQL> SELECT TITLE, SCOST, DCOST, (SCOST - DCOST) FROM SOFTWARE DESCENDING ORDER
BY (SCOST-DCOST);

6. Display the details of those who draw the same salary.

INPUT: SQL> SELECT P.PNAME, P.SAL FROM PROGRAMMER P, PROGRAMMER T WHERE P.PNAME <>

T.PNAME AND P.SAL = T.SAL;(OR)

INPUT: SQL>SELECT PNAME,SAL FROM PROGRAMMER T WHERE PNAME<>T.PNAME AND SAL= T.SAL;

7. Display total salary spent for each job category.

INPUT: SQL>SELECT JOB,SUM (SAL) FROM EMP GROUP BY JOB;


OUTPUT:
JOB SUM(SAL)
--------- ----------
ANALYST 6000
CLERK 23050
MANAGER 8275

13
PRESIDENT 5000
SALESMAN 5600
assistant 2200
clerk 2003
7 rows selected.

8. Display lowest paid employee details under each manager.

INPUT: SQL>SELECT ENAME, SAL FROM EMP WHERE SAL IN (SELECT MIN(SAL) FROM EMP GROUP BY
MGR);
OUTPUT:
ENAME SAL
---------- ----------
CHAI 3
JAMES 950
MILLER 1000
ADAMS 1100
russel 2200
5 rows selected.

9. Display number of employees working in each department and their department name.

INPUT: SQL> SELECT DNAME, COUNT (ENAME) FROM EMP, DEPT WHERE EMP.DEPTNO=DEPT.DEPTNO

GROUP BY DNAME;

OUTPUT:
DNAME COUNT(ENAME)
-------------- ------------
ACCOUNTING 3
RESEARCH 5
SALES 9

10. Display the sales cost of package developed by each programmer.

INPUT: SQL> SELECT PNAME, SUM(SCOST) FROM SOFTWARE GROUP BY PNAME;

OUTPUT:
PNAME SUM(SCOST)
-------------------- ----------
john 12000
kamala 12000
raju 12333
3 rows selected.

11. Display the number of packages sold by each programmer.

INPUT: SQL>SELECT PNAME, COUNT(TITLE) FROM SOFTWARE GROUP BY PNAME;

OUTPUT:
PNAME COUNT(TITLE)
-------------------- ------------

14
john 1
kamala 1
raju 1
ramana 1
rani 1
5 rows selected.

12. Display the number of packages in each language for which the development cost is less than
thousand.

INPUT: SQL>SELECT DEVIN, COUNT(TITLE) FROM SOFTWARE WHERE DCOST < 1000 GROUP BY DEVIN;

OUTPUT:
DEVIN COUNT(TITLE)
---------- ------------
cobol 1

13. Display each institute name with number of students.

INPUT: SQL> SELECT SPLACE, COUNT(PNAME) FROM STUDY GROUP BY SPLACE;


OUTPUT:
SPLACE COUNT(PNAME)
-------------------- ------------
BDPS 2
BITS 1
BNRILLIANI 1
COIT 1
HYD 1
5 rows selected.

13. How many copies of package have the least difference between development and selling cost, were
sold?

INPUT: SQL>select SOLD FROM SOFTWARE WHERE SCOST – DCOST=(SELECT MIN(SCOST – DCOST)
FROM SOFTWARE);

OUTPUT:
SOLD
---------
11

14. Which is the costliest package developed in Pascal.

INPUT: SQL>SELECT TITLE FROM SOFTWARE WHERE DEVIN = ‘PASCAL’ AND DCOST = (SELECT
MAX(DCOST) FROM SOFTWARE WHERE DEVIN = ‘PASCAL’);

OUTPUT:
no rows selected

15. Which language was used to develop most no .of packages?

15
INPUT: SQL>SELECT DEVIN, COUNT (*) FROM SOFTWARE GROUP BY DEVIN HAVING COUNT(*)

= (SELECT MAX(COUNT(*) ) FROM SOFTWARE GROUP BY DEVIN);

OUTPUT:
DEVIN COUNT(*)
---------- ----------
jsp 2

16.Who are the male programmers earning below the average salary of female programmers?

INPUT: SQL>SELECT PNAME FROM PROGRAMMER WHERE SAL < (SELECT AVG(SAL) FROM PROGRAMMER
WHERE SEX = ‘F’) AND SEX = ‘M’;

OUTPUT:
PNAME
--------------------
vijay

17. Display the details of software developed by the male programmers earning more than 3000/-.

INPUT: SQL> SELECT PROGRAMMER.PNAME, TITLE, DEVIN FROM PROGRAMMER, SOFTWARE WHERE SAL
> 3000 AND SEX = ‘M’ AND PROGRAMMER.PNAME = SOFTWARE.PNAME;

OUTPUT:

no rows selected

18. Display the details of software developed in c language by female programmers of Pragathi.

INPUT: SQL>SELECT SOFTWARE.PNAME, TITLE, DEVIN, SCOST, DCOST, SOLD FROM PROGRAMMER,
SOFTWARE, STUDY WHERE DEVIN = ‘C’ AND SEX =’F’ AND SPLACE = ‘PRAGATHI’ AND
PROGRAMMER.PNAME = SOFTWARE.PNAME AND SOFTWARE.PNAME = STUDY.PNAME;

16
RESULT:

Thus the given problem statements were solved using nested queries and group by & other
clauses.

6. PROBLEMS BASED ON VIEWS, SYNONYM, SEQUENCE & INDEX

AIM:

To solve the problem statements based on views, synonym, sequence and Indexes.

OVERVIEW:

VIEW:

A view is simply the representation of a SQL statement that is stored in memory so that it can
easily be re-used. Its also referred as logical table.

SYNTAX:

CREATE OR REPLACE VIEW <view name > AS < select statement >

SYNONYM:

A synonym is an alias or alternate name for a table, view, sequence, or other schema object.
They are used mainly to make it easy for users to access database objects owned by other users.

SYNTAX:

CREATE OR REPLACE SYNONYM <synonym_name> FOR <object_name>

SEQUENCE:

A sequence is a database object from which multiple users may generate unique integers. User
can use sequences to automatically generate primary key values.

INDEXES:

Database system uses indexes to avoid the need for large-table, full-table scans and disk sorts,
which are required when the SQL optimizer cannot find an efficient way to service the SQL query.

17
SYNTAX:
CREATE INDEX <index_name> ON <table_name(attribute)>

PROBLEM STATEMENTS:

1. Create a view from single table containing all columns from the base table.

SQL>CREATE VIEW VIEW1 AS (SELECT * FROM PROGRAMMER);

2. Create a view from single table with selected columns.

SQL>CREATE A VIEW VIEW2 AS (SELECT PNAME,DOB,DOJ,SEX,SAL FROM PROGRAMMER);

3. Create a view from two tables with all columns.

SQL>CREATE VIEW XYZ AS SELECT * FROM PROGRAMMER FULL NATURAL JOIN SOFTWARE;

4. Create a view from two tables with selected columns.

SQL> CREATE VIEW LMN AS (SELECT PROGRAMMER, PNAME, TITLE, DEVIN FROM PROGRAMMER,
SOFTWARE WHERE SAL < 3000 AND PROGRAMMER.PNAME = SOFTWARE.PNAME);

5. Check all DML commands with above 4 views.

INPUT: SQL> INSERT INTO VIEW1 VALUES (‘RAMU’,’12-SEP-03’,’28-JAN-85’ ,’F’, ’DBASE’,’ ORACLE’,
74000);
OUTPUT:

1 row created;

INPUT: SQL>UPDATE VIEW1 SET SALARY =50000 WHERE PNAME LIKE ‘SARVAN’;
OUTPUT:

1 row updated.

Note: update command does not works for all queries on views.

INPUT: SQL>DELETE FROM VIEW1 WHERE PNAME LIKE ‘SMITH’;


OUTPUT:

18
1 row deleted.

1. Drop views which you generated.

INPUT: SQL>DROP VIEW VIEW1;


OUTPUT:

View dropped.

2. Create a synonym for a table created by other user.

SQL> CREATE SYNONYM EMP FOR SP.EMPLOYE;

3. Try to perform all DML operations through the created synonym.

SQL> INSERT INTO EMP VALUES (‘EMP10’,’LARA’,’MAINTENANCE’,’27-OCT-1998’);


OUTPUT:

1 row created.

SQL> UPDATE EMP SET EMPNAME=’BRAIN LARA’ WHERE EMPID=’EMP10’;


OUTPUT:

1 row Updated.

4. Create a sequence to generate unique value for empid field in the employee table while inserting.

SQL> CREATE SEQUENCE EMP_SEQ

START WITH 1000

INCREMENT BY 1

NOCACHE

NOCYCLE;

OUTPUT:

Sequence Created.

SQL> INSERT INTO EMP VALUES (EMP_SEQ.NEXTVAL,’SAHA’,’TESTING’,’27-DEC-1999’);


OUTPUT:

1 row created;

5. Create index for city attribute in employee table.

SQL> CREATE INDEX EMP_INDEX ON EMP(CITY);

OUTPUT:

Index Created.

19
RESULT:

Thus the given problem statements based on views, synonyms, sequences and indexes were
solved.

7. CREATING DATABASE

AIM:

To create database and also to create relationship among database.

COMMAND OVERVIEW:

SYNTAX:
CREATE DATABASE [ database ]
{ USER SYS IDENTIFIED BY password
| USER SYSTEM IDENTIFIED BY password
| CONTROLFILE REUSE
| MAXDATAFILES integer
| MAXINSTANCES integer
| CHARACTER SET charset
| NATIONAL CHARACTER SET charset
| SET DEFAULT
{ BIGFILE | SMALLFILE } TABLESPACE
| database_logging_clauses
| tablespace_clauses
| set_time_zone_clause
};
PROBLEM STATEMENT:

1. Create a new database by the name student_db with required features.

SQL> CREATE DATABASE STUDENT_DB


USER SYS IDENTIFIED BY ORACLE
USER SYSTEM IDENTIFIED BY ORACLE
DATAFILE ‘C:\oracle\oradata\ORA11\SYSTEM01.DBF’ SIZE 325M REUSE AUTOEXTEND ON NEXT

20
10240K MAXSIZE UNLIMITED
SYSAUX DATAFILE ‘C:\oracle\oradata\ORA11\SYSAUX01.DAT’ SIZE 120M REUSE AUTOEXTEND
ON NEXT 5M MAXSIZE 2048M
DEFAULT TABLESPACE USERS DATAFILE ‘C:\oracle\oradata\ORA11\USERS01.DBF’ SIZE 50M
REUSE AUTOEXTEND ON MAXSIZE UNLIMITED;

RESULT:

Thus the database was created with the specified parameters.


8. HIGH LEVEL PROGRAMMING LANGUAGE EXTENSION (PL/SQL BLOCKS)
AIM:
To solve the given problem statements using PL/SQL blocks.

PL/SQL BLOCK:
PL/SQL is a block-structured language, meaning that PL/SQL programs are divided and written in
logical blocks of code. Each block consists of three sub-parts:

1. Declarations: This section starts with the keyword DECLARE. It is an optional section and defines all
variables, cursors, subprograms, and other elements to be used in the program.
2: Executable Commands: This section is enclosed between the keywords BEGIN and END and it is a
mandatory section. It consists of the executable PL/SQL statements of the program. It should have at
least one executable line of code, which may be just a NULL command to indicate that nothing should be
executed.
3: Exception Handling: This section starts with the keyword EXCEPTION. This section is again optional and
contains exception(s) that handle errors in the program.

Every PL/SQL statement ends with a semicolon (;). PL/SQL blocks can be nested within other PL/SQL
blocks using BEGIN and END.

SYNTAX:
DECLARE
<declarations section>
BEGIN
<executable command(s)>
EXCEPTION
<exception handling>
END;

21
PROBLEM STATEMENTS:
REFERED TABLES:
Employe (emp_id,emp_name,dept_id,basic,hra,da,pf,net);

1. Create a PL/SQL block for inserting values in the Employee table. Only emp_id, emp_name,
department & basic should be received as input while executing the block and for the rest of the fields
the values need to be calculated as given below.
Calculations:
HRA=50% OF BASIC
DA=20% OF BASIC
PF=7% OF BASIC
NETPAY=BASIC+DA+HRA-PF

INPUT:

DECLARE
ENO1 employe.emp_id%type;
ENAME1 employe.emp_name%type;
DEPTNO1 employe.dept_id%type;
BASIC1 employe.basic%type;
HRA1 employe.HRA%type;
DA1 employe.DA%type;
PF1 employe.pf%type;
NETPAY1 employe.net%type;
BEGIN
ENO1:=&ENO1;
ENAME1:='&ENAME1';
DEPTNO1:=&DEPTNO1;
BASIC1:=&BASIC1;
HRA1:=(BASIC1*50)/100;
DA1:=(BASIC1*20)/100;
PF1:=(BASIC1*7)/100;
NETPAY1:=BASIC1+HRA1+DA1-PF1;

INSERT INTO EMPLOYE VALUES (ENO1, ENAME1, DEPTNO1, BASIC1, HRA1, DA1, PF1, NETPAY1);
END;

22
OUTPUT:

SQL> @BASIC
Enter value for eno1: 104
old 11: ENO1:=&ENO1;
new 11: ENO1:=104;
Enter value for ename1: SRINIVAS REDDY
old 12: ENAME1:='&ENAME1';
new 12: ENAME1:='SRINIVAS REDDY';
Enter value for deptno1: 10
old 13: DEPTNO1:=&DEPTNO1;
new 13: DEPTNO1:=10;
Enter value for basic1: 6000
old 14: BASIC1:=&BASIC1;
new 14: BASIC1:=6000;

PL/SQL procedure successfully completed.

SQL>/
Enter value for eno1: 105
old 11: ENO1:=&ENO1;
new 11: ENO1:=105;
Enter value for ename1: CIRAJ
old 12: ENAME1:='&ENAME1';
new 12: ENAME1:='CIRAJ';
Enter value for deptno1: 10
old 13: DEPTNO1:=&DEPTNO1;
new 13: DEPTNO1:=10;
Enter value for basic1: 6000
old 14: BASIC1:=&BASIC1;
new 14: BASIC1:=6000;

PL/SQL procedure successfully completed.

SQL> SELECT * FROM EMPDET;


OUTPUT:

23
EMP_ID EMP_ NAME DEPT_ID BASIC HRA DA PF NETPAY
--------- ------------------------------ --------- --------- --------- --------- --------- -----------------------
101 GAYLE 10 5000 2500 1000 350 8150
102 SARVAN 20 5000 2500 1000 350 8150
103 POINTING 20 5500 2750 1100 385 8965
104 SMITH 10 6000 3000 1200 420 9780
105 KALIS 10 6000 3000 1200 420 9780

2. Create a PL/SQL block for updating records in Employe table where the user should provide the
emp_id and the new basic salary and thus the HRA,DA, PF and NETPAY should get calculated and
updated accordingly.

INPUT:
DECLARE
ENO1 employe.emp_id%type;
BASIC1 employe.basic%type;
HRA1 employe.HRA%type;
DA1 employe.DA%type;
PF1 employe.pf%type;
NETPAY1 employe.net%type;
BEGIN
ENO1:=&ENO1;
BASIC1:=&BASIC1;
HRA1:=(BASIC1*50)/100;
DA1:=(BASIC1*20)/100;
PF1:=(BASIC1*7)/100;
NETPAY1:=BASIC1+HRA1+DA1-PF1;

UPDATE EMPLOYE SET BASIC=BASIC1, HRA=HRA1, DA=DA1, PF=PF1, NETPAY=NETPAY1 WHERE


EMP_ID=ENO1;

END;
OUTPUT:
SQL>/
Enter value for eno1: 105

24
old 11: ENO1:=&ENO1;
new 11: ENO1:=105;
Enter value for basic1: 8000
old 14: BASIC1:=&BASIC1;
new 14: BASIC1:=8000;

PL/SQL procedure successfully completed.

3. Create a PL/SQL block for showing the new netpay after getting new basic salary for a particular
employee. Display the new netpay along the old netpay without updating in the table. Also If no
customer found with the given customer id then show appropriate error message.
INPUT:
DECLARE
ENO employe.emp_id%type;
BASICNW employe.basic%type;
HRANW employe.HRA%type;
DANW employe.DA%type;
PFNW employe.pf%type;
NETPAY employe.net%type;
NETPAYNW employe.net%type;
BEGIN
ENO:=&ENO;
BASICNW:=&BASICNW;
HRANW:=(BASICNW*50)/100;
DANW:=(BASICNW*20)/100;
PFNW:=(BASICNW*7)/100;
NETPAY1:=BASICNW+HRA1+DA1-PF1;
SELECT NET INTO NETPAY FROM EMPLOYE WHERE EMP_ID=ENO;
DBMS_OUTPUT.PUT_LINE(EN0|| ‘ ‘ || NETPAY || ‘ ‘ || NETPAY1);
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('NO SUCH EMPLOYEE.');
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('ERROR');
END;

25
RESULT:
Thus PL/SQL statements were written for inserting & updating the rows in the EMPLOYE table.

9. PROCEDURES

AIM:

To solve the given problem statements using procedures.

PL/SQL PROCEDURES:

An Oracle stored procedure is a program stored in an Oracle database. The following are the
advantages of using procedures.

Better performance: Oracle stored procedures load once into the shared pool and remain there
unless they become paged out. Subsequent executions of the Oracle stored procedure are far faster than
executions of external code.

Coupling of data with behaviour: DBAs can use naming conventions to couple relational tables
with the behaviors associated with a table by using Oracle stored procedures as "methods". If all
behaviors associated with the employee table are prefixed with the table name--employee.hire,
employee.give_raise, for example--the data dictionary can be queries to list all behaviors associated with
a table (select * from dba_objects where owner = 'EMPLOYEE'), and it's easy to identify and reuse code
via stored procedures.

Isolation of code: Since all SQL is moved out of the external programs and into the Oracle stored
procedures, the application programs become nothing more than calls to Oracle stored procedures. As
such, it becomes very simple to swap out one database and swap in another one.

SYNTAX:

CREATE [OR REPLACE] PROCEDURE procedure_name (parameters list)


IS
<declaration_section>

BEGIN
<executable_section>

EXCEPTION

26
<exception_section>

END;

PROBLEM STATEMENTS:
REFERRED TABLES:

Borrow(acc_no , rollno, date_issue);

1. Write a procedure to insert a record in borrower relation. Before inserting check whether the book
is available or not.

CREATE OR REPLACE PROCEDURE PROC_BORROW(ACCNO NUMBER, ROLL VARCHAR, DOI DATE)

IS

CNT NUMBER(5);

BEGIN

SELECT COUNT(*) INTO CNT FROM BORROW WHERE ACC_NO=ACCNO;

IF(CNT=0)

THEN

INSERT INTO BORROW VALUES (ACCNO,ROLL,DOI);

ELSE

DBMS_OUTPUT.PUT_LINE(‘BOOK NOT AVAILABLE’);

END IF;

END;

OUTPUT:

SQL> @ e:\proc.sql;

Procedure Created.

SQL> exec pro1(‘123’,’CS01’,’27-OCT-2013’);

Procedure successfully completed.

SQL> SELECT * FROM BORROW;

ACC_NOROLLNO DOI

27
---------- ------------ ------------

123 CS01 27-OCT-2013

128 CS10 18-OCT-2013

2. Write a procedure to insert a record in borrower relation with the above constraints and also
ensure that the member has not borrowed more than three books.

CREATE OR REPLACE PROCEDURE PROC_BORROW(ACCNO NUMBER, ROLL VARCHAR, DOI DATE)

IS

CNT NUMBER(5);

BEGIN

SELECT COUNT(*) INTO CNT FROM BORROW WHERE ACC_NO=ACCNO;

IF(CNT=0)

THEN

SELECT COUNT(*) INTO CNT1 FROM BORROW WHERE ROLLNO=ROLL;

IF(CNT1<4)

THEN

INSERT INTO BORROW VALUES (ACCNO,ROLL,DOI);

END IF;

ELSE

DBMS_OUTPUT.PUT_LINE(‘BOOK NOT AVAILABLE’);

END IF;

END;

OUTPUT:

SQL> @ e:\proc.sql;

Procedure Created.

28
Result:
Thus PL/SQL Procedures were created to solve the given problem statements.

10.FUNCTIONS

AIM:

To solve the given problem statements using PL/SQL functions.

PL/SQL FUNCTION:

A PL/SQL function is same as a procedure except that it returns a value. A standalone function is
created using the CREATE FUNCTION statement.

SYNTAX

CREATE [OR REPLACE] FUNCTION function_name (parameter_name [IN | OUT | IN OUT] type [, ...])

RETURN return_datatype

{IS | AS}

BEGIN

< function_body >

END;

PROBLEM STATEMENT:

REFERRED TABLES:

Transaction (accno number(5), amount number(7,2), trans_type varchar(5),dot date);

1. Create a function to insert the records into the transaction table, after performing each transaction
in the transaction table show the net balance of the particular account.

CREATE OR REPLACE FUNCTION FUNC_TRANS (ACC_ID NUMBER,AMNT NUMBER,TYPE VARCHAR)

RETURN NUMBER

29
IS

BALANCE NUMBER;

BEGIN

INSERT INTO TRANSACTION VALUES(ACC_ID,AMNT,TYPE);

SELECT SUM(AMNT) INTO BALANCE FROM TRANSACTION WHERE ACC_NO=ACC_ID;

RETURN BALANCE;

END;

PL/SQL FUNCTION:

DECLARE

BALANCE_AMNT NUMBER(6);

ACC_NO VARCHAR(5);

AMNT NUMBER(5);

TYPE VARCHAR(2);

RESULT NUMBER(5);

BEGIN

ACC_NO:=’&ACC_NO’;

AMNT:=’&AMNT’;

TYPE:=’&TYPE’;

BALANCE_AMNT:=FUNC1(ACC_ID,AMNT,TYPE);

DBMS_OUTPUT.PUT_LINE(‘TOTAL AMOUNT ‘|| TOTAL_AMNT);

END;

OUTPUT:

SQL> @E:\SQL\FUNCPLSQL.SQL;

Enter value for accno: 001

Enter value for amt: 25000

Enter value for type=’CRDT’

30
RESULT 26000

PL/SQL procedure successfully completed.

RESULT:
Thus PL/SQL functions were created to solve the given problem statements.

11.TRIGGERS
AIM:
To solve the given problem statements using triggers.

PL/SQL TRIGGERS:
Triggers are stored programs, which are automatically executed or fired when some events occur.
Triggers are, in fact, written to be executed in response to any of the following events:
A database manipulation (DML) statement (DELETE, INSERT, or UPDATE).
A database definition (DDL) statement (CREATE, ALTER, or DROP).
A database operation (SERVERERROR, LOGON, LOGOFF, STARTUP, or SHUTDOWN).
Triggers could be defined on the table, view, schema, or database with which the event is associated.
Benefits of Triggers
Generating some derived column values automatically
Enforcing referential integrity
Event logging and storing information on table access
Auditing
Synchronous replication of tables
Imposing security authorizations
Preventing invalid transactions.

SYNTAX:
CREATE OR REPLACE TRIGGER < trigger_name >
{BEFORE | AFTER | INSTEAD OF }
{INSERT [OR] | UPDATE [OR] | DELETE} [OF col_name]
ON < table_name >
[REFERENCING OLD AS o NEW AS n]
[FOR EACH ROW]

31
WHEN < condition >
DECLARE
< Declaration-statements >
BEGIN
< Executable-statements >
EXCEPTION
< Exception-handling-statements >
END;

PROBLEM STATEMENT:

REFERRED TABLES:

Account ( accnt_no,cst_id,acnt_type,last_trans_date,balance )

Account_bckup(accnt_no,last_trans_date,balance)

Loan (ln_id,cst_id,ln_amount,ln_date);

1. Create a trigger for Account relation such that whenever a record is inserted in the Account table
the same record also gets inserted in the backup table.

CREATE OR REPLACE TRIGGER TRIG_ACNT_BCKUP AFTER INSERT ON ACCOUNT

FOR EACH ROW

DECLARE

BEGIN

INSERT INTO ACCOUNT_BCKUP VALUES (:NEW.ACCNT_NO, :NEW.LAST_TRANS_DATE,


:NEW.BALANCE);

END;

OUTPUT:

SQL> @e:/plsql/accnt_trig.sql

Trigger Created.

SQL> INSERT INTO ACCOUNT VALUES (‘AC010’,’CST011’,’SVNG’,’27-AUG-2013’,12000);

1 Row inserted.

SQL> SELECT * FROM ACCOUNT_BCKUP;

ACCNO LAST_TRANS_DATE BALANCE

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

32
AC010 27-AUG-2013 12,000

2. Create a trigger for account relation such that whenever account record is inserted in account
relation with negative relation then that record should also be inserted in the loan relation with positive
balance.

CREATE OR REPLACE TRIGGER TRIG_LOAN AFTER INSERT ON ACCOUNT

FOR EACH ROW

DECLARE

BEGIN

IF(:NEW.BALANCE<0)

THEN

INSERT INTO LOAN VALUES (:NEW.ACCNT_NO, :NEW.CST_ID, -(:NEW.BALANCE), SYSDATE);

END IF;

END;

OUTPUT:

SQL> @e:/plsql/loan_trig.sql

Trigger Created.

SQL> INSERT INTO ACCOUNT VALUES (‘AC011’,’CST011’,’SVNG’,’27-DEC-2013’,-8000);

1 Row inserted.

SQL> SELECT * FROM LOAN;

LN_ID CST_ID LN_AMOUNT LN_DATE

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

AC010 CST011 8000 30-DEC-2013

33
Result:
Thus the triggers were created accordingly to solve the given problem statements.

12.MINI PROJECT
PAY ROLL PROCESSING
AIM
To create a database for payroll processing system using SQL and implement it using VB
PROCEDURE
 Create a database for payroll processing which request the using SQL
 Establish ODBC connection
 In the administrator tools open data source ODBC
 Click add button and select oracle in ORA home 90,click finish
 A window will appear given the data source home as oracle and select TNS source name
as orcl1 and give the user id and password.
 Create necessary table to store the data
 Write appropriate Program VB to connect it with database.
Report Generation
 In a new Project select the Add Data Environment designer from the Project menu.
 In project explorer select Data Environment1 connection1 will appear.
 Select connection1 and press Right Click and select Properties.
 Select Microsoft OLEDB provider for Oracle and press Next.
 Enter Server name, User name and Password and choose allow saving password.
 Click Test Connection to check whether the connection is established with Oracle and click
Ok button.
 Select connection and press Right Click and Choose Add Command.
 In Properties of command1 set the database object as table and the object name as the
desired table which is used for reports and click Ok.
 Select project menu and click Add Reports.
 In the Data Report property change Data Source as Data Environment1 and Data Member
as Command1

34
 Drag command1 and drop it in the detail section of Data Report.
 Select Project Properties and change the start from object to Data Report.
 Run the application to View the Report.

SAMPLE CODING
//FORM 1
Private Sub emp_Click()
Form2.Show
End Sub
Private Sub exit_Click()
Unload Me
End Sub
Private Sub salary_Click()
Form3.Show
End Sub
//FORM 2
Private Sub add_Click()
Adodc1.Recordset.AddNew
MsgBox "Record added"
End Sub
Private Sub clear_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
End Sub
Private Sub delte_Click()
Adodc1.Recordset.Delete
MsgBox "Record Deleted"
If Adodc1.Recordset.EOF = True Then
Adodc1.Recordset.MovePrevious
End If
End Sub
Private Sub exit_Click()
Unload Me
End Sub
Private Sub main_Click()
Form1.Show
End Sub
Private Sub modify_Click()
Adodc1.Recordset.Update

35
End Sub
//FORM 3
Private Sub add_Click()
Adodc1.Recordset.AddNew
MsgBox "Record added"
End Sub
Private Sub clear_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
End Sub
Private Sub delte_Click()
Adodc1.Recordset.Delete
MsgBox "Record Deleted"
If Adodc1.Recordset.EOF = True Then
Adodc1.Recordset.MovePrevious
End If
End Sub
Private Sub exit_Click()
Unload Me
End Sub
Private Sub main_Click()
Form1.Show
End Sub
Private Sub modify_Click()
Adodc1.Recordset.Update
End Sub

SAMPLE OUTPUT

36
37
38
39
RESULT
Thus the design and implementation of payroll processing system using SQL, VB was
successfully done

BANKING SYSTEM
AIM
To develop a mini project for banking system.
PROCEDURE:
 Create the DB for banking system source request the using SQL
 Establish ODBC connection
 In the administrator tools open data source ODBC
 Click add button and select oracle in ORA home 90,click finish
 A window will appear given the data source home as oracle and select TNS source name
as orcl1 and give the user id and password.
 Create necessary table to store the data
 Add ADODC project select component and check ms ADO data control click ok
 Click customs and property window and window will appear and select ODBC data source
name as oracle and click apply as the some window

SAMPLE CODING
//FORM 1
Private Sub ACCOUNT_Click()
Form2.Show
End Sub
Private Sub EXIT_Click()
Unload Me
End Sub

40
Private Sub TRANSACTION_Click()
Form3.Show
End Sub
//FORM 2
Private Sub CLEAR_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
End Sub
Private Sub DELETE_Click()
Adodc1.Recordset.DELETE
MsgBox "record deleted"
Adodc1.Recordset.MoveNext
If Adodc1.Recordset.EOF = True Then
Adodc1.Recordset.MovePrevious
End If
End Sub
Private Sub EXIT_Click()
Unload Me
End Sub
Private Sub HOME_Click()
Form1.Show
End Sub
Private Sub INSERT_Click()
Adodc1.Recordset.AddNew
End Sub
Private Sub TRANSACTION_Click()
Form3.Show
End Sub
Private Sub UPDATE_Click()
Adodc1.Recordset.UPDATE
MsgBox "record updated successfully"
End Sub
//FORM 3
Private Sub ACCOUNT_Click()
Form2.Show
End Sub
Private Sub CLEAR_Click()
Text1.Text = ""
Text2.Text = ""
End Sub
Private Sub DEPOSIT_Click()
Dim s As String
s = InputBox("enter the amount to be deposited")
Text2.Text = Val(Text2.Text) + Val(s)
A = Text2.Text
MsgBox "CURRENT BALANCE IS Rs" + Str(A)
Adodc1.Recordset.Save
Adodc1.Recordset.UPDATE
End Sub

41
Private Sub EXIT_Click()
Unload Me
End Sub
Private Sub HOME_Click()
Form1.Show
End Sub
Private Sub WITHDRAW_Click()
Dim s As String
s = InputBox("enter the amount to be deleted")
Text2.Text = Val(Text2.Text) - Val(s)
A = Text2.Text
MsgBox "current balance is Rs" + Str(A)
Adodc1.Recordset.Save
Adodc1.Recordset.UPDATE
End

OUTPUT

42
43
44
RESULT
Thus the mini project for banking system by using VB,SQL was done.

45
LIBRARY MANAGEMENT SYSTEM
AIM
To develop an application software for Library Management System.
PROCEDURE
 Create the DB for library management system source request the using SQL
 Establish ODBC connection
 In the administrator tools open data source ODBC
 Click add button and select oracle in ORA home 90,click finish
 A window will appear given the data source home as oracle and select TNS source name
as orcl1 and give the user id and password.
 Create necessary table to store the data
 Add ADODC project select component and check ms ADO data control click ok
 Click customs and property window and window will appear and select ODBC data source
name as oracle and click apply as the some window
SAMPLE CODING
//FORM 1
Private Sub Command1_Click()
Me.Hide
Load Form5
Form5.Visible = True
End Sub
Private Sub Command2_Click()
Me.Hide
Load Form3
Form3.Visible = True
End Sub
Private Sub Command3_Click()
Me.Hide
Load Form4
Form4.Visible = True
End Sub
Private Sub Command4_Click()
End
End Sub
//FORM 2:
Private Sub Command1_Click()
Data1.Recordset.AddNew
Data1.Recordset.Fields("roll_no") = Val(Text1.Text)
Data1.Recordset.Fields("name") = Text2.Text
Data1.Recordset.Fields("dep") = Text3.Text
Data1.Recordset.Fields("year") = Val(Text4.Text)
Data1.Recordset.Update
End Sub

46
Private Sub Command2_Click()
b = MsgBox("Are you sure u want to delete it...", vbOKCancel + vbExclamation)
If b = 1 Then
Data1.Recordset.Delete
Data1.Recordset.MoveNext
MsgBox "Record is deleted"
Else
End If
End Sub
Private Sub Command3_Click()
a = InputBox("Enter the student roll number", roll_no)
Data1.Recordset.MoveFirst
On Error GoTo jvm
While Not Data1.Recordset.Fields("roll_no") = Val(a)
Data1.Recordset.MoveNext
End
End Sub
Sub Command5_Click()
End
End Sub
Private Sub Command6_Click()
Unload Me
Load Form1: Form1.Visible = True
End Sub
FORM 3:
Private Sub Command1_Click()
Data1.Recordset.AddNew
Data1.Recordset.Fields("book_id") = Val(Text1.Text)
Data1.Recordset.Fields("name") = Text2.Text
Data1.Recordset.Fields("author") = Text3.Text
Data1.Recordset.Fields("copies") = Val(Text4.Text)
Data1.Recordset.Update
End Sub
Private Sub Command2_Click()
b = MsgBox("Are you sure u want to delete it...", vbOKCancel + vbExclamation)
If b = 1 Then
Data1.Recordset.Delete
Data1.Recordset.MoveNext
MsgBox "Record is deleted"
Else
End If
End Sub
Private Sub Command3_Click()
Dim a As String
a = InputBox("Enter the book name", book_name)
Data1.Recordset.MoveFirst
On Error GoTo jvm
Do Until Data1.Recordset.EOF
If Data1.Recordset("book_name") = a Then
Text1 = Data1.Recordset.Fields("book_id")

47
MsgBox "The book id is " + Data1.Recordset.Fields("book_id") + " It has " +
Data1.Recordset.Fields("copies")
End If
Data1.Recordset.MoveNext
Loop
jvm:
End Sub
Private Sub Command5_Click()
End
End Sub
Private Sub Command6_Click()
Unload Me
Load Form1: Form1.Visible = True
End Sub
Private Sub Text6_Change()
If Text6.Text = 0 Then
MsgBox "No copies Available"
End If
End Sub
FORM 4:
Dim x As Date
Private Sub Command1_Click()
Data1.Recordset.AddNew
Data1.Recordset.Fields("roll_no") = Val(Text1.Text)
Data1.Recordset.Fields("name") = Text2.Text
Data1.Recordset.Fields("book_id") = Val(Text3.Text)
Data1.Recordset.Fields("book_name") = Text4.Text
Data1.Recordset.Fields("curr_date") = Val(Text5.Text)
Data1.Recordset.Fields("date_of_return") = Val(Text6.Text)
Data1.Recordset.Update
End Sub
Private Sub Command2_Click()
b = MsgBox("Are you sure u want to delete it...", vbOKCancel + vbExclamation)
If b = 1 Then
Data1.Recordset.Delete
Data1.Recordset.MoveNext
MsgBox "Record is deleted"
Else
End If
End Sub
Private Sub Command3_Click()
a = InputBox("Enter the student roll number", roll_no)
Data1.Recordset.MoveFirst
On Error GoTo jvm
While Not Data1.Recordset.Fields("roll_no") = Val(a)
Data1.Recordset.MoveNext
End
End Sub
Private Sub Command4_Click()
Text6.Text = DateValue(Text5) + 15

48
End Sub
Private Sub Command5_Click()
End
End Sub
Private Sub Command6_Click()
Unload Me
Load Form1: Form1.Visible = True
End Sub
Private Sub Command7_Click()
Dim n As Double
n = (DateValue(Text7) - DateValue(Text5))
If n > 15 Then
n = n - 15
n=n/2
Text8 = n
End If
End Sub
Private Sub Text5_Click()
If Val(Text4.Text) = 0 Then
MsgBox "No copies Available"
End If
End Sub
FORM 5:
Private Sub Command1_Click()
Form2.Show
End Sub
Private Sub Command2_Click()
Form6.Show
End Sub
Private Sub Command3_Click()
Form1.Show
End Sub
FORM 6:
Private Sub Command1_Click()
Form1.Show
End Sub

SAMPLE OUTPUT

49
50
51
52
53
RESULT
Thus the mini project for library management system by using VB, oracle was done.

54

You might also like