Sie sind auf Seite 1von 70

LESs G.V.

Acharya Institute of Engineering and Technology,


Shelu
Department of Civil Engineering

Lab Manual
Database and Information Retrieval System
Class - Semester: SE-III

G.V.ACHARYA INSTITUTE OF ENGINEERING AND TECHNOLOGY, SHELU

DBIR LAB
1. Introduction to Structured Query Language(SQL)
2. Basic DDL & DML commands
3. Advanced DDL & DML commands
4. To implement queries using aggregate functions, arithmetic, logical,
comparison operators
5. Entity relationship model and Relational model
6. Triggers
7. Nested sub queries
8. PL/SQL cursor
9. Views
10. Menu driven application using VB
Contemporary Experiments (beyond syllabus)
1. PL/SQL procedures and functions
2. Dynamic SQL

GVAIET/NBA-2013/CRITERIA 7.2/T-LP/CIVIL/SE/SEM III/LAB MANUAL/DBIR/REV.0/1.7.2016

Page 2

G.V.ACHARYA INSTITUTE OF ENGINEERING AND TECHNOLOGY, SHELU

Index

Ex. No

Name of the Experiment

Page
Number

Introduction to Structured Query Language(SQL)

Basic DDL & DML commands

11

Advanced DDL & DML commands

18

To implement queries using aggregate functions, arithmetic,


logical, comparison operators

25

Entity relationship model and Relational model

34

Triggers

41

Nested sub queries

48

PL/SQL cursor

53

Views

57

10

Menu driven application using VB

64

GVAIET/NBA-2013/CRITERIA 7.2/T-LP/CIVIL/SE/SEM III/LAB MANUAL/DBIR/REV.0/1.7.2016

Page 3

G.V.ACHARYA INSTITUTE OF ENGINEERING AND TECHNOLOGY, SHELU

EVALUATION SHEET

Sr.n
o.

List of experiments

Date of
performance

Date of
Submission

Grade/
marks

Remarks

Total marks
Average marks

Ex. No. 1
Date:

INTRODUCTION TO STRUCTURED QUERY LANGUAGE


(SQL)

GVAIET/NBA-2013/CRITERIA 7.2/T-LP/CIVIL/SE/SEM III/LAB MANUAL/DBIR/REV.0/1.7.2016

Page 4

G.V.ACHARYA INSTITUTE OF ENGINEERING AND TECHNOLOGY, SHELU

AIM: To study Structured Query Language (SQL).


INTRODUCTION TO SQL
SQL (Structured Query Language) is a database computer language designed for
the retrieval and management of data in relational database management systems
(RDBMS), database schema creation and modification, and database object access
control management.
SQL is a programming language for querying and modifying data and managing
databases. SQL was standardized first by the ANSI and (later) by the ISO. Most
database management systems implement a majority of one of these standards and
add their proprietary extensions. SQL allows the retrieval, insertion, updating, and
deletion of data.
A database management system also includes management and administrative
functions. Most -- if not all -- implementations also include a Command-line Interface
(SQL/CLI) that allows for the entry and execution of the language commands, as
opposed to only providing an API intended for access from a GUI.
The first version of SQL was developed at IBM by Donald D. Chamberlin and
Raymond F. Boyce in the early 1970s. This version, initially called SEQUEL, was
designed to manipulate and retrieve data stored in IBM's original relational database
product; System R. IBM patented their version of SQL in 1985, while the SQL
language was not formally standardized until 1986, by the American National
Standards Institute (ANSI) as SQL-86. Subsequent versions of the SQL standard have
been released by ANSI and as International Organization for Standardization (ISO)
standards.
Originally designed as a declarative query and data manipulation language,
variations of SQL have been created by SQL database management system (DBMS)
vendors that add procedural constructs, control-of-flow statements, user-defined data
types, and various other language extensions. With the release of the SQL:1999
standard, many such extensions were formally adopted as part of the SQL language
via the SQL Persistent Stored Modules (SQL/PSM) portion of the standard.
Common criticisms of SQL include a perceived lack of cross-platform portability
between vendors, inappropriate handling of missing data (see Null (SQL)), and
unnecessarily complex and occasionally ambiguous language grammar and semantics.
FEATURES OF SQL:
SQL is both an easy-to-understand language and a comprehensive tool for managing
data. Some of the major features of SQL are

Vendor independence

Portability across computer systems

SQL standards

IBM endorsement and commitment (DB2)

Microsoft commitment (SQL Server , ODBC, and ADO)


GVAIET/NBA-2013/CRITERIA 7.2/T-LP/CIVIL/SE/SEM III/LAB MANUAL/DBIR/REV.0/1.7.2016

Page 5

G.V.ACHARYA INSTITUTE OF ENGINEERING AND TECHNOLOGY, SHELU

Relational foundation
High-level, English-like structure
Interactive, ad hoc queries
Programmatic database access
Multiple views of data
Complete database language
Dynamic data definition
Client/server architecture
Enterprise application support
Extensibility and object technology
Internet database access
Java integration (JDBC)
Industry infrastructure

SQL COMMANDS
SQL Consisting of DDL, DML, DCL, TCL COMMANDS.
DDL
Data Definition Language (DDL) statements are used to define the database structure
or schema.
DDL Commands: Create, Alter, Drop, Rename, Truncate
CREATE - to create objects in the database
ALTER - alters the structure of the database
DROP - delete objects from the database
TRUNCATE - remove all records from
spaces allocated for the records are removed
RENAME - rename an object

table,

including

all

DML
Data Manipulation Language (DML) statements are used for managing data within
schema objects
DML Commands: Insert ,Update, Delete, Select
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
SELECT - retrieve data from the a database

DCL
Data Control Language (DCL) statements is used to create roles, permissions, and
referential integrity as well it is used to control access to database by securing it.
GVAIET/NBA-2013/CRITERIA 7.2/T-LP/CIVIL/SE/SEM III/LAB MANUAL/DBIR/REV.0/1.7.2016

Page 6

G.V.ACHARYA INSTITUTE OF ENGINEERING AND TECHNOLOGY, SHELU

DCL Commands: Grant, Revoke


GRANT - gives user's access privileges to database
REVOKE- withdraw access privileges given
command

with

the

GRANT

TCL
Transaction Control (TCL) statements are used to manage the changes made by DML
statements. It allows statements to be grouped together into logical transactions.
TCL Commands: Commit, Rollback, Save point
COMMIT - save work done
SAVEPOINT - identify a point in a transaction to which you can
later roll back
ROLLBACK - restore database to original since the last COMMIT
SYNTAXS OF COMMANDS
CREATE TABLE
CREATE TABLE table_name
(
column_name1 data_type,
column_name2 data_type,
column_name3 data_type,
....
);
ALTER A TABLE
To add a column in a table
ALTER TABLE table_name
ADD column_name datatype;
To delete a column in a table
ALTER TABLE table_name
DROP COLUMN column_name;
To modify data type an existing Column
ALTER TABLE table-name
modify(column-name datatype);
GVAIET/NBA-2013/CRITERIA 7.2/T-LP/CIVIL/SE/SEM III/LAB MANUAL/DBIR/REV.0/1.7.2016

Page 7

G.V.ACHARYA INSTITUTE OF ENGINEERING AND TECHNOLOGY, SHELU

To rename a column
ALTER TABLE table-name
rename old-column-name to column-name;
DROP TABLE
DROP TABLE table_name;
TRUNCATE TABLE
TRUNCATE TABLE table_name;
RENAME QUERY
RENAME TABLE old-table-name to new-table-name;
INSERT
INSERT INTO table_name
VALUES (value1, value2, value3,...);
( OR )
INSERT INTO table_name (column1, column2, column3,...)
VALUES (value1, value2, value3,...);
UPDATE
UPDATE table_name
SET column1=value, column2=value2,...
WHERE some_column=some_value;
DELETE
DELETE FROM table_name
WHERE some_column=some_value;
SELECT (To display records of table)
SELECT column_name(s)
FROM table_name;
CONCLUSION:
GVAIET/NBA-2013/CRITERIA 7.2/T-LP/CIVIL/SE/SEM III/LAB MANUAL/DBIR/REV.0/1.7.2016

Page 8

G.V.ACHARYA INSTITUTE OF ENGINEERING AND TECHNOLOGY, SHELU

Timely
Submission
(5)

Presentation
(5)

Understanding
(10)

Total (20)

Signature

VIVA QUESTIONS:
1) What is SQL?
2) Which are different SQL commands?
3) Enlist features of SQL.
4) What is query to display all records from table?
5) What is DBMS?

GVAIET/NBA-2013/CRITERIA 7.2/T-LP/CIVIL/SE/SEM III/LAB MANUAL/DBIR/REV.0/1.7.2016

Page 9

G.V.ACHARYA INSTITUTE OF ENGINEERING AND TECHNOLOGY, SHELU

Ex. No. 2
Date:

BASIC DDL & DML COMMANDS

GVAIET/NBA-2013/CRITERIA 7.2/T-LP/CIVIL/SE/SEM III/LAB MANUAL/DBIR/REV.0/1.7.2016

Page 10

G.V.ACHARYA INSTITUTE OF ENGINEERING AND TECHNOLOGY, SHELU

AIM:
To create a college database with the following tables
o Student table with the fields rollno, name, mark1, mark2, mark3 and
the rollno must be unique.
o Dept table with the fields unique deptid and deptname
o Staff table with the fields staffid, name, designation
QUERIES:
SQL> create table student(rollno number(5) primary key, name varchar(20),mark1
number(3),mark2 number(3),mark3 number(3));
SQL>create table dept(deptid number(3) primary key,dname varchar(20));
SQL>create table staff(staffid number(3),name varchar(20), designation varchar(20));
SQL>insert into student values(&rollno,&name,&mark1,&mark2,&mark3);
SQL>insert into dept values(&deptid,&dname);
SQL>insert into staff values(&staffid,&name,&designation);
Write down the queries for the following.
i.
Describe the structure of all tables.
SQL> desc student;
SQL> desc dept;
SQL> desc staff;
ii.

Add a new column total, percentage in student table.\


SQL> alter table student add(total number(3),percentage number(5,2));
SQL> update student set total=mark1+mark2+mark3;
SQL> update student set percentage=total/3;

iii.

Add a new column dept in student table.


SQL> alter table student add(deptid number(3) references dept(deptid));

iv.

Add a new column grade in student table and update it as if


percentage >75 then first class with distinction, if percentage>60
and <75 then first class otherwise second class.
SQL> alter table student add(grade varchar(35));
SQL> update student set grade=case when percentage>75.0 then First
class with distinction when percentage>60.0 and percentage<75.0 then
first class else second class end;

v.

Make staffid in staff table as primary key and add new column
deptid as foreign key refers deptid in dept table.
SQL> alter table staff add primary key(staffid);
SQL> alter table staff add(deptid number(3));
SQL> alter table staff add constraint dpk foreign key(deptid) references
dept(deptid);

vi.

List the name and rollno of all the students.

GVAIET/NBA-2013/CRITERIA 7.2/T-LP/CIVIL/SE/SEM III/LAB MANUAL/DBIR/REV.0/1.7.2016

Page 11

G.V.ACHARYA INSTITUTE OF ENGINEERING AND TECHNOLOGY, SHELU

SQL> select rollno,name from student;


vii.

List the name of students who scored 90 marks in all subject.


SQL>select name from student where mark1>90 and mark2>90 and
mark3>90;

viii.

List the name of students whose name starts with s and ends with a
SQL>select name from student where name likes%a;

ix.

List out the Asst professors in COMP dept


SQL>select name from staff where designation=asst.prof and deptid=1;

x.

Find the number of depts.


SQL>select count(deptid) from dept;

xi.

Find the student with minimum total


SQL>select min(total) from student;

xii.

Find the class average percentage and maximum percentage in a


class.
SQL>select avg(percentage),max(percentage) from student;

xiii.

List the number of students with grade First class with distinction
SQL>select count(rollno) from student where grade=first class with
distinction;

xiv.

List rollno, name of the student in descending order of total


SQL>select rollno,name from student order by total desc;

xv.

Find the number of students in each dept


SQL>select count(rollno) from student group by deptid;

xvi.

Find the depts in which the students are enrolled


SQL>select distinct deptid from student;

xvii.

Find all lecturers in the college


SQL>Select * from staff where designation=lecturer;

xviii. Find the student whose name is ends with i.


SQL>select * from student where name like %i;
xix.

Delete the student details whose name is Raju


SQL>delete from student where name=raju;

xx.

Delete all staffs belongs to EXTC dept


SQL>delete from staff where deptid=6;

OUTPUT:

GVAIET/NBA-2013/CRITERIA 7.2/T-LP/CIVIL/SE/SEM III/LAB MANUAL/DBIR/REV.0/1.7.2016

Page 12

G.V.ACHARYA INSTITUTE OF ENGINEERING AND TECHNOLOGY, SHELU

GVAIET/NBA-2013/CRITERIA 7.2/T-LP/CIVIL/SE/SEM III/LAB MANUAL/DBIR/REV.0/1.7.2016

Page 13

G.V.ACHARYA INSTITUTE OF ENGINEERING AND TECHNOLOGY, SHELU

GVAIET/NBA-2013/CRITERIA 7.2/T-LP/CIVIL/SE/SEM III/LAB MANUAL/DBIR/REV.0/1.7.2016

Page 14

G.V.ACHARYA INSTITUTE OF ENGINEERING AND TECHNOLOGY, SHELU

CONCLUSION:

GVAIET/NBA-2013/CRITERIA 7.2/T-LP/CIVIL/SE/SEM III/LAB MANUAL/DBIR/REV.0/1.7.2016

Page 15

G.V.ACHARYA INSTITUTE OF ENGINEERING AND TECHNOLOGY, SHELU

Timely
Submission (5)

Presentation
(5)

Understanding (10)

Total (20)

Signature

VIVA QUESTIONS:
1) Which are different DDL commands?
2) Which are different DML commands?
3) What is syntax to describe structure of table?
4) How to add records to table?
5) What is use of Primary Key?

GVAIET/NBA-2013/CRITERIA 7.2/T-LP/CIVIL/SE/SEM III/LAB MANUAL/DBIR/REV.0/1.7.2016

Page 16

G.V.ACHARYA INSTITUTE OF ENGINEERING AND TECHNOLOGY, SHELU

Ex. No. 3

ADVANCED DDL AND DML COMMANDS

Date:
AIM:
GVAIET/NBA-2013/CRITERIA 7.2/T-LP/CIVIL/SE/SEM III/LAB MANUAL/DBIR/REV.0/1.7.2016

Page 17

G.V.ACHARYA INSTITUTE OF ENGINEERING AND TECHNOLOGY, SHELU

To Create employee table with the fields EMPNO(Primary key), ENAME,


JOB, MGR, HIREDATE, SAL, COMM, DEPTNO,AGE. Dept table with fields
DEPTNO(Primary key),DNAME,LOC
QUERIES:
SQL> create table employee(empno number(5)primary key,ename varchar(20),job
varchar(20),mgr number(5),doj date,salary number(7),deptno number(2),age
number(3));
Table created.
SQL> create table department(deptno number(2) primary key,dname
varchar(20),location varchar(20));
Table created.
SQL> alter table employee add constraint fk foreign key(deptno) references
department(deptno);
Table altered.
SQL> desc employee;
Name
Null?
Type
----------------------------------------- -------- ---------------------EMPNO
NOT NULL
NUMBER(5)
ENAME
VARCHAR2(20)
JOB
VARCHAR2(20)
MGR
NUMBER(5)
DOJ
DATE
SALARY
NUMBER(7)
DEPTNO
NUMBER(2)
AGE
NUMBER(3)
SQL> desc department;
Name
Null? Type
----------------------------------------- -------- ---------------------DEPTNO
NOT NULL
NUMBER(2)
DNAME
VARCHAR2(20)
LOCATION
VARCHAR2(20)
SQL> insert into department values(&deptno,'&dname','&location');
Enter value for deptno: 1
Enter value for dname: account
Enter value for location: madurai
old 1: insert into department values(&deptno,'&dname','&location')
new 1: insert into department values(1,'account','madurai')
1 row created.
GVAIET/NBA-2013/CRITERIA 7.2/T-LP/CIVIL/SE/SEM III/LAB MANUAL/DBIR/REV.0/1.7.2016

Page 18

G.V.ACHARYA INSTITUTE OF ENGINEERING AND TECHNOLOGY, SHELU

SQL> select * from department;


DEPTNO DNAME
LOCATION
---------- -------------------- -------------------1 account
madurai
2 sales
madurai
3 production
sivakasi
SQL> insert into employee
values(&empno,'&ename','&job',&mgr,'&doj',&salary,&deptno,&age);
Enter value for empno: 101
Enter value for ename: siva
Enter value for job: manager
Enter value for mgr: 0
Enter value for doj: 01-mar-2005
Enter value for salary: 24000
Enter value for deptno: 1
Enter value for age: 23
old 1: insert into employee
values(&empno,'&ename','&job',&mgr,'&doj',&salary,&deptno,&age)
new 1: insert into employee values(101,'siva','manager',0,'01-mar-2005',24000,1,23)
1 row created.
SQL> select * from employee;
EMPNO ENAME JOB MGR DOJ
---------- ---------- ---------101
siva manager
0
01-MAR-05
102
mani clerk
1
01-SEP-05
103
sarpa manager
0
23-MAR-06
104
rajan supervisor 103 10-OCT-07
105
viji manager 0
04-JUN-00
106
ramya salesrep
105 01-JUL-01
107
kalai
worker
103 02-APR-03
7 rows selected.

SALARY
24000
10000
250000
14000
20000
14000
1600

DEPTNO AGE
1
1
3
3
2
2
2

23
34
24
30
25
27
26

1. List all employee names and their salaries, whose salary lies between 1500/and 3500/- both inclusive.
SQL> select ename from employee where salary between 1500 and 3500;
2. List all employee names and their and their manager whose manager is 7902
or 7566 0r 7789.
SQL> select ename from employee where mgr in(7902,7566,7789);
3. List all employees which starts with either J or T.
SQL> select ename from employee where ename like 'J%' or ename like 'T%';
4. List all jobs available in employee table.
SQL> select distinct job from employee;
GVAIET/NBA-2013/CRITERIA 7.2/T-LP/CIVIL/SE/SEM III/LAB MANUAL/DBIR/REV.0/1.7.2016

Page 19

G.V.ACHARYA INSTITUTE OF ENGINEERING AND TECHNOLOGY, SHELU

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


SQL> select ename,salary,salary+0.15*salary from employee;
6. Find how many job titles are available in employee table.
SQL> select count(distinct job) from employee;
7. What is the difference between maximum and minimum salaries of
employees in the organization?
SQL>SQL> select max(salary)-min(salary) from employee;
8. Display all employee names and salary whose salary is greater than minimum
salary of the company and job title starts with M.
SQL> select ename,salary from employee where job like 'm%' and salary>(select
min(salary) from employee);
9. Display lowest paid employee details under each manager.
SQL> select min(salary) from employee group by mgr
10. Display number of employees working in each department and their
department name.
SQL> select dname,count(ename) from employee,department where
employee.deptno=department.deptno group by dname;
11. Find all managers in each dept appointed after year 2000
SQL> select ename from employee where job='manager' and extract(year from
doj)>2000;
12. Find all manager and his working place whose age is above 35 with salary
more than 1 lakh.
SQL> select ename from employee where job='manager' and age>35 and
salary>100000;

OUTPUT:

GVAIET/NBA-2013/CRITERIA 7.2/T-LP/CIVIL/SE/SEM III/LAB MANUAL/DBIR/REV.0/1.7.2016

Page 20

G.V.ACHARYA INSTITUTE OF ENGINEERING AND TECHNOLOGY, SHELU

GVAIET/NBA-2013/CRITERIA 7.2/T-LP/CIVIL/SE/SEM III/LAB MANUAL/DBIR/REV.0/1.7.2016

Page 21

G.V.ACHARYA INSTITUTE OF ENGINEERING AND TECHNOLOGY, SHELU

CONCLUSION:

GVAIET/NBA-2013/CRITERIA 7.2/T-LP/CIVIL/SE/SEM III/LAB MANUAL/DBIR/REV.0/1.7.2016

Page 22

G.V.ACHARYA INSTITUTE OF ENGINEERING AND TECHNOLOGY, SHELU

Timely
Submission (5)

Presentation
(5)

Understanding (10)

Total (20)

Signature

VIVA QUESTIONS:
1) What is syntax of GROUP BY clause?
2) What is use of BETWEEN clauses?
3) What is use of DISTINCT?
4) What is use of WHERE clause?
5) What is syntax of WHERE clause?

GVAIET/NBA-2013/CRITERIA 7.2/T-LP/CIVIL/SE/SEM III/LAB MANUAL/DBIR/REV.0/1.7.2016

Page 23

G.V.ACHARYA INSTITUTE OF ENGINEERING AND TECHNOLOGY, SHELU

Ex. No. 4.
Date:

TO IMPLEMENT QUERIES USING AGGREGATE


FUNCTIONS, ARITHMATIC, LOGICAL, COMPARISON
OPERATORS

AIM:

GVAIET/NBA-2013/CRITERIA 7.2/T-LP/CIVIL/SE/SEM III/LAB MANUAL/DBIR/REV.0/1.7.2016

Page 24

G.V.ACHARYA INSTITUTE OF ENGINEERING AND TECHNOLOGY, SHELU

To create the table employee with attributes ESSN, sname, mname, lname,
DOB, address, gender, salary, deptno. Create the table department with the attributes
depno, dname, mssn, deptloc. Create the table project entity set with attributes
prono(P.K) proname, Proloc,depno. Create the workson entity set with the attributes
ESSN(F.K) prono(F.K), Hours per week. Create the dependant entity set with the
attributes essn(F.K),depname, Gender, dob, relationship
QUERIES:
SQL> create table deptmt(depno number(3) primary key,dname varchar(20),mssn
number(4),deptloc varchar(20));
Table created.
SQL> create table emp(essn number(4) primary key,sname varchar(20),mname
varchar(10),lname varchar(20),dob date,address varchar(25),gender varchar(1),salary
number(5),depno number(3) references deptmt (depno));
Table created.
SQL> create table project(prono number(3) primary key,proname varchar(20),proloc
varchar(20),depno number(3) references deptmt(depno));
Table created.
SQL> create table workson(essn number(4) references emp(essn),prono number(5)
references project,hoursperweek number(2));
Table created.
SQL> create table dependent(essn number(4) references emp(essn),depname
varchar(20),gender varchar(1),dob date,relationship varchar(20));
Table created.
SQL> insert into deptmt values(&depno,'&dname',&mssn,'&deptloc');
Enter value for depno: 1
Enter value for dname: research
Enter value for mssn: 1001
Enter value for deptloc: madurai
old 1: insert into deptmt values(&depno,'&dname',&mssn,'&deptloc')
new 1: insert into deptmt values(1,'research',1001,'madurai')
1 row created.
SQL> insert into emp
values(&essn,'&sname','&mname','&lname','&dob','&address','&gender',&salary,&de
pno);
Enter value for essn: 1001
Enter value for sname: john
GVAIET/NBA-2013/CRITERIA 7.2/T-LP/CIVIL/SE/SEM III/LAB MANUAL/DBIR/REV.0/1.7.2016

Page 25

G.V.ACHARYA INSTITUTE OF ENGINEERING AND TECHNOLOGY, SHELU

Enter value for mname: b


Enter value for lname: smith
Enter value for dob: 10-jan-1990
Enter value for address: madurai
Enter value for gender: m
Enter value for salary: 20000
Enter value for depno: 1
old 1: insert into emp
values(&essn,'&sname','&mname','&lname','&dob','&address','&gender',&salary
new 1: insert into emp values(1001,'john','b','smith','10-jan1990','madurai','m',20000,1)
1 row created.
SQL> insert into workson values(&essn,&prono,&hoursperweek);
Enter value for essn: 1001
Enter value for prono: 101
Enter value for hoursperweek: 5
old 1: insert into workson values(&essn,&prono,&hoursperweek)
new 1: insert into workson values(1001,101,5)
1 row created.
SQL> insert into dependent
values(&essn,'&depname','&gender','&dob','&relationship');
Enter value for essn: 1001
Enter value for depname: kalai
Enter value for gender: f
Enter value for dob: 29-jan-1984
Enter value for relationship: daughter
old 1: insert into dependent
values(&essn,'&depname','&gender','&dob','&relationship')
new 1: insert into dependent values(1001,'kalai','f','29-jan-1984','daughter')
1 row created.
SQL> desc deptmt;
Name
Null? Type
----------------------------------------- -------- -------------------DEPNO
NOT NULL NUMBER(3)
DNAME
VARCHAR2(20)
MSSN
NUMBER(4)
DEPTLOC
VARCHAR2(20)
SQL> desc emp;
Name
Null? Type
----------------------------------------- -------- -------------------ESSN
NOT NULL NUMBER(4)
SNAME
VARCHAR2(20)
MNAME
VARCHAR2(10)
GVAIET/NBA-2013/CRITERIA 7.2/T-LP/CIVIL/SE/SEM III/LAB MANUAL/DBIR/REV.0/1.7.2016

Page 26

G.V.ACHARYA INSTITUTE OF ENGINEERING AND TECHNOLOGY, SHELU

LNAME
DOB
ADDRESS
GENDER
SALARY
DEPNO

VARCHAR2(20)
DATE
VARCHAR2(25)
VARCHAR2(1)
NUMBER(5)
NUMBER(3)

SQL> desc project;


Name
Null? Type
----------------------------------------- -------- -------------------PRONO
NOT NULL NUMBER(3)
PRONAME
VARCHAR2(20)
PROLOC
VARCHAR2(20)
DEPNO
NUMBER(3)
SQL> desc workson;
Name
Null? Type
----------------------------------------- -------- -------------------ESSN
NUMBER(4)
PRONO
NUMBER(5)
HOURSPERWEEK
NUMBER(2)
SQL> desc dependent;
Name
Null? Type
----------------------------------------- -------- -------------------ESSN
NUMBER(4)
DEPNAME
VARCHAR2(20)
GENDER
VARCHAR2(1)
DOB
DATE
RELATIONSHIP
VARCHAR2(20)
SQL> select * from emp;
ESSN SNAME MNAME LNAME DOB ADDRESS G SALARY
1001 john
b
smith 10-JAN-50madurai m 20000
2001 sam
b
raj
18-AUG-81sivakasi m 30000
3001 siva
e
raja
10-DEC-92new houston m 15000

DEPNO
1
2
3

SQL> select * from deptmt;


DEPNO DNAME
MSSN DEPTLOC
---------- -------------------- ---------- -------------------1 research
1001 madurai
2 sales
2001 sivakasi
3 accounts
3001 theni
SQL> select * from project;
PRONO PRONAME
PROLOC
---------- -------------------- -------------------- ----------

DEPNO

GVAIET/NBA-2013/CRITERIA 7.2/T-LP/CIVIL/SE/SEM III/LAB MANUAL/DBIR/REV.0/1.7.2016

Page 27

G.V.ACHARYA INSTITUTE OF ENGINEERING AND TECHNOLOGY, SHELU

101 securityservice
madurai
102 productx
stafford
103 payrollprocessing theni

1
1
3

SQL> select * from workson;


ESSN
PRONO HOURSPERWEEK
---------- ---------- -----------1001
101
5
1001
102
8
3001
103
7
SQL> select * from dependent;
ESSN DEPNAME G DOB
RELATIONSHIP
---------- -------------------- - --------- -------------------1001 kalai
f 29-JAN-84 daughter
2001 sam
m 02-MAR-90 son
3001 fathima
f 03-JUN-76 wife
Write the queries to do the following
1. Retrieve the birthdate and address of the employee(s) whose name is John B.
Smith
SQL> select dob,address from emp where sname='john' and mname='b' and
lname='smith';
2. Retrieve the name and address of all employees who work for the Research
department
SQL> select sname,lname,address from emp,deptmt where dname='research' and
emp.depno=deptmt.depno;
3. For every project located in Stafford, list the project number, the controlling
department number, and the department managers last name, address, and
birthdate.
SQL> select p.prono,d.depno,e.lname,e.address,e.dob from emp e,project p,deptmt d
where p.proloc='stafford' and e.depno=d.depno and e.depno=p.depno and
d.mssn=e.essn;
4.Retrieve all employees whose address is in Houston
SQL> select sname,lname from emp where address like '%houston';
5. Show the resulting salaries if every employee working on the ProductX
project is given a 10 percent raise.
SQL> select sname,lname,1.1*salary from emp e,workson w,project p where
e.essn=w.essn and p.prono=w.prono and p.proname='productx';
6. Retrieve all employees in department 5 whose salary is between $30,000 and
$40,000.
SQL> select * from emp where salary between 30000 and 40000 and depno=5;
GVAIET/NBA-2013/CRITERIA 7.2/T-LP/CIVIL/SE/SEM III/LAB MANUAL/DBIR/REV.0/1.7.2016

Page 28

G.V.ACHARYA INSTITUTE OF ENGINEERING AND TECHNOLOGY, SHELU

7. Retrieve a list of employees and the projects they are working on, ordered by
department and, within each department, ordered alphabetically by last name,
first name.
SQL> select d.dname,e.lname,e.sname,p.proname from deptmt d,emp e,workson
w,project p where e.depno=d.depno and e.essn=w.essn and p.prono=w.prono order by
d.dname,e.lname,e.sname;
8. Retrieve the name of each employee who has a dependent with the same first
name and same sex as the employee
SQL> select e.sname,e.lname from emp e where e.essn in(select essn from dependent
where e.sname=depname and e.gender=gender);
9. Find the sum of the salaries of all employees of the Research department, as
well as the maximum salary, the minimum salary, and the average salary in this
department.
SQL> select sum(salary),max(salary),min(salary),avg(salary) from emp,deptmt where
deptmt.depno=emp.depno and deptmt.dname='research';
10. Count the number of distinct salary values in the database
SQL> select count(distinct salary) from emp;
11. Retrieve the total number of employees in the company and the number of
employees in the Research department.
SQL> select count(*) from emp,deptmt where deptmt.depno=emp.depno and
deptmt.dname='research';
12. Find all employees who were born during the 1950s
SQL> select sname,lname from emp where extract(year from dob)=1950;

OUTPUT:

GVAIET/NBA-2013/CRITERIA 7.2/T-LP/CIVIL/SE/SEM III/LAB MANUAL/DBIR/REV.0/1.7.2016

Page 29

G.V.ACHARYA INSTITUTE OF ENGINEERING AND TECHNOLOGY, SHELU

GVAIET/NBA-2013/CRITERIA 7.2/T-LP/CIVIL/SE/SEM III/LAB MANUAL/DBIR/REV.0/1.7.2016

Page 30

G.V.ACHARYA INSTITUTE OF ENGINEERING AND TECHNOLOGY, SHELU

CONCLUSION:

GVAIET/NBA-2013/CRITERIA 7.2/T-LP/CIVIL/SE/SEM III/LAB MANUAL/DBIR/REV.0/1.7.2016

Page 31

G.V.ACHARYA INSTITUTE OF ENGINEERING AND TECHNOLOGY, SHELU

Timely
Submission (5)

Presentation
(5)

Understanding (10)

Total (20)

Signature

VIVA QUESTIONS:
1) Enlist the aggregate functions.
2) Which are the logical operators in SQL.
3) What is LIKE operator?
4) What is syntax of min() function?
5) What is syntax of sum() function?

GVAIET/NBA-2013/CRITERIA 7.2/T-LP/CIVIL/SE/SEM III/LAB MANUAL/DBIR/REV.0/1.7.2016

Page 32

G.V.ACHARYA INSTITUTE OF ENGINEERING AND TECHNOLOGY, SHELU

Ex. No. 5.
ER MODEL
Date:
AIM:

To construct ER Diagram for the following situations.


The company is organized into departments. Each department has unique
name, unique number and a particular employee who manages the department.
Keep track of the start date when the employee begins managing the

GVAIET/NBA-2013/CRITERIA 7.2/T-LP/CIVIL/SE/SEM III/LAB MANUAL/DBIR/REV.0/1.7.2016

Page 33

G.V.ACHARYA INSTITUTE OF ENGINEERING AND TECHNOLOGY, SHELU

departments. The department may be in several locations. The department


controls no.of projects each of which has unique number and single location.
Store each employees name, number, address, salary, gender and date of birth.
An employee is assigned to one department but may work on several projects
which are not necessarily controlled by the same department. Keep track of
the no.of hours per week that an employee works on each project. Also keep
track of the direct supervisor of each employee. Keep track of the dependence
of each employee for insurance purpose. Keep each dependence first name,
gender, date of birth and relationship to that employee.
USER REQUIREMENTS:
ENTITIES:
Employee(name,number,address,gender,dob);
Department(name,deptno,location)
Project(projname,projno,location)
Dependence(name,gender,dob,relationship)
RELATIONSHIP:

Worksfor(number,deptno)
Workson(hours,projno,number)
Supervises(number)
Manages(startdate,deptno,number,name)
Controlledby(deptno,projno)
Dependent(number,name)

ER MODEL FOR EMPLOYEE DATABASE


Street
City
Gender
nam
e

address

nam
e
dep
tno

GVAIET/NBA-2013/CRITERIA 7.2/T-LP/CIVIL/SE/SEM III/LAB MANUAL/DBIR/REV.0/1.7.2016

locatio
n
Page 34

G.V.ACHARYA INSTITUTE OF ENGINEERING AND TECHNOLOGY, SHELU

Department
fo
r

W
or
s k

Employee

DO
B

name

DOJ
e
nag
ma
s

Su
ise perv
s

Number

location
pro
jno

Project
ll
tro
n
Co by
ed

Wo
s o rk
n

Dependence

DOB

relationshi
p

Name
hours

De
p
s o end
n

Gender

RELATIONAL MODEL FOR EMPLOYEE DATABASE

GVAIET/NBA-2013/CRITERIA 7.2/T-LP/CIVIL/SE/SEM III/LAB MANUAL/DBIR/REV.0/1.7.2016

Page 35

G.V.ACHARYA INSTITUTE OF ENGINEERING AND TECHNOLOGY, SHELU

ER MODEL FOR COLLGE DATABASE

GVAIET/NBA-2013/CRITERIA 7.2/T-LP/CIVIL/SE/SEM III/LAB MANUAL/DBIR/REV.0/1.7.2016

Page 36

G.V.ACHARYA INSTITUTE OF ENGINEERING AND TECHNOLOGY, SHELU

RELATIONAL MODEL FOR COLLEGE DATABASE

GVAIET/NBA-2013/CRITERIA 7.2/T-LP/CIVIL/SE/SEM III/LAB MANUAL/DBIR/REV.0/1.7.2016

Page 37

G.V.ACHARYA INSTITUTE OF ENGINEERING AND TECHNOLOGY, SHELU

CONCLUSION:

Timely
Submission (5)

Presentation
(5)

Understanding (10)

Total (20)

Signature

VIVA QUESTIONS:
1) What is ER diagram?
2) What is relational model?
3) What is Entity?
4) What is attribute?
5) Which are the relationship types?

GVAIET/NBA-2013/CRITERIA 7.2/T-LP/CIVIL/SE/SEM III/LAB MANUAL/DBIR/REV.0/1.7.2016

Page 38

G.V.ACHARYA INSTITUTE OF ENGINEERING AND TECHNOLOGY, SHELU

GVAIET/NBA-2013/CRITERIA 7.2/T-LP/CIVIL/SE/SEM III/LAB MANUAL/DBIR/REV.0/1.7.2016

Page 39

G.V.ACHARYA INSTITUTE OF ENGINEERING AND TECHNOLOGY, SHELU

Ex. No. 6.
TRIGGERS
Date:
AIM:
To Create the following table
1. Books(ISBN,Title,Author,Price,Pub_year)
2. Stock(ISBN,Stock_quantity,reorderlevel,reorderquantity)
3. Customers(Custid,custname,address)
4. Orders(orderno,custid,orderdate)
5. Orderlist(orderno,ISBN,quantity,totalprice,shipdate)
QUERIES:
SQL> create table books(isbn number(5) primary key,title varchar(25),author
varchar(20),price number (5,2),pubyear number(4));
Table created.
SQL> create table stock(isbn number(5) references books(isbn));
Table created.
SQL> alter table stock add(stockquantity number(4),reorderlevel
number(3),reorderquantity number(4));
Table altered.
SQL> create table customers(custid number(5) primary key,cname
varchar(25),address varchar(25));
Table created.
SQL> create table orders(orderno number(4) primary key,custid number(5)
references customers(custid) ,orderdate date);
Table created.
SQL> create table orderlist(orderno number(4) references orders(orderno),isbn
number(5) primary key, quantity number(5),totalprice number(5,2),shipdate date);
Table created.
SQL> insert into books values(&isbn,'&title','&author',&price,&pubyear);

GVAIET/NBA-2013/CRITERIA 7.2/T-LP/CIVIL/SE/SEM III/LAB MANUAL/DBIR/REV.0/1.7.2016

Page 40

G.V.ACHARYA INSTITUTE OF ENGINEERING AND TECHNOLOGY, SHELU

Enter value for isbn: 10001


Enter value for title: dbms
Enter value for author: date
Enter value for price: 500
Enter value for pubyear: 2005
old 1: insert into books values(&isbn,'&title','&author',&price,&pubyear)
new 1: insert into books values(10001,'dbms','date',500,2005)
1 row created.
SQL> select * from books;
ISBN TITLE

AUTHOR

PRICE PUBYEAR

---------- ------------------------- -------------------- ---------- ---------10001 dbms

date

10002 data structure

500

weiss

10003 cryptography

2005

700

stallings

400

2002
2006

SQL> insert into stock


values(&isbn,&stockquantity,&reorderlevel,&reorderquantity);
Enter value for isbn: 10001
Enter value for stockquantity: 10
Enter value for reorderlevel: 3
Enter value for reorderquantity: 5
old 1: insert into stock
values(&isbn,&stockquantity,&reorderlevel,&reorderquantity)
new 1: insert into stock values(10001,10,3,5)
1 row created.
SQL> select * from stock;
ISBN STOCKQUANTITY REORDERLEVEL REORDERQUANTITY
---------- ------------- ------------ --------------10001

10

10002

20

10

10

10003

15

SQL> insert into customers values(&custid,'&cname','&address');


Enter value for custid: 1

GVAIET/NBA-2013/CRITERIA 7.2/T-LP/CIVIL/SE/SEM III/LAB MANUAL/DBIR/REV.0/1.7.2016

Page 41

G.V.ACHARYA INSTITUTE OF ENGINEERING AND TECHNOLOGY, SHELU

Enter value for cname: siva


Enter value for address: madurai
old 1: insert into customers values(&custid,'&cname','&address')
new 1: insert into customers values(1,'siva','madurai')
1 row created.
SQL> select * from customers;
CUSTID CNAME

ADDRESS

---------- ------------------------- ------------------------1 siva

madurai

2 raja

theni

3 kalai

salem

SQL> insert into orders values(&orderno,&custid,'&orderdate');


Enter value for orderno: 101
Enter value for custid: 1
Enter value for orderdate: 01-jan-2010
old 1: insert into orders values(&orderno,&custid,'&orderdate')
new 1: insert into orders values(101,1,'01-jan-2010')
1 row created.
SQL> select * from orders;
ORDERNO

CUSTID ORDERDATE

---------- ---------- --------101

1 01-JAN-10

102

1 05-JUN-10

103

3 18-AUG-10

a. Fire a trigger before insert whenever the ordered quantity is less than the
available stock quantity or the shipdate is less than the orderdate then
display the message The ordered quantity is not available or shipping date
should be greater than order date respectively.
SQL> set serveroutput on;
SQL> create or replace trigger trigger1
2 before insert on orderlist for each row
3 declare
4 qn number(5);
GVAIET/NBA-2013/CRITERIA 7.2/T-LP/CIVIL/SE/SEM III/LAB MANUAL/DBIR/REV.0/1.7.2016

Page 42

G.V.ACHARYA INSTITUTE OF ENGINEERING AND TECHNOLOGY, SHELU

5 dat date;
6 begin
7 select stockquantity into qn from stock where isbn=:new.isbn;
8 select orderdate into dat from orders where orderno=:new.orderno;
9 if :new.quantity>qn then
10 dbms_output.put_line('ordered quantity is not available');
11 end if;
12 if months_between(:new.shipdate,dat)<0 then
13 dbms_output.put_line('ordered date is greater than shipment date');
14 end if;
15 end;
16 /
Trigger created.
SQL> insert into orderlist
values(&orderno,&quantity,&totalprice,'&shipdate',&isbn);
Enter value for orderno: 102
Enter value for quantity: 15
Enter value for totalprice: 1000
Enter value for shipdate: 01-mar-2010
Enter value for isbn: 10001
old 1: insert into orderlist
values(&orderno,&quantity,&totalprice,'&shipdate',&isbn)
new 1: insert into orderlist values(102,15,1000,'01-mar-2010',10001)
1 row created.
b. Fire a trigger after update of price, when the new price is greater than the old
price, update the total price of the corresponding isbn number.
SQL> Create or replace trigger trigger3
2 After update on books for each row
3 When(new.price>old.price)
4 Begin
5 Update orderlist set totalprice=:new.price*quantity where isbn=:new.isbn;
6 End;
7
8 /

GVAIET/NBA-2013/CRITERIA 7.2/T-LP/CIVIL/SE/SEM III/LAB MANUAL/DBIR/REV.0/1.7.2016

Page 43

G.V.ACHARYA INSTITUTE OF ENGINEERING AND TECHNOLOGY, SHELU

Trigger created.
SQL> update books set price=600 where isbn=10001;
1 row updated.
SQL> select * from orderlist;
ORDERNO QUANTITY TOTALPRICE SHIPDATE

ISBN

---------- ---------- ---------- --------- ---------101

1800 01-MAR-10

10001

102

15

9000 01-MAR-10

10001

101

1200 01-JAN-09

10001

c. Fire a trigger after delete of an order from the orders table, which would
delete the corresponding order from the orderlist table.
SQL> Create or replace trigger trigger4
2 After delete on orders for each row
3 Begin
4 Delete from orderlist where orderno=:old.orderno;
5 End;
6 /
Trigger created.
SQL> select * from orders;
ORDERNO

CUSTID ORDERDATE

---------- ---------- --------101

1 01-JAN-10

102

1 05-JUN-10

103

3 18-AUG-10

SQL> delete from orders where orderno=102;


1 row deleted.
SQL> select * from orderlist;
ORDERNO QUANTITY TOTALPRICE SHIPDATE

ISBN

---------- ---------- ---------- --------- ---------101

1800 01-MAR-10

101

1200 01-JAN-09

10001
10001

GVAIET/NBA-2013/CRITERIA 7.2/T-LP/CIVIL/SE/SEM III/LAB MANUAL/DBIR/REV.0/1.7.2016

Page 44

G.V.ACHARYA INSTITUTE OF ENGINEERING AND TECHNOLOGY, SHELU

CONCLUSION:

Timely
Submission (5)

Presentation
(5)

Understanding (10)

Total (20)

Signature

VIVA QUESTIONS:
1) What is Trigger?
2) What is use of Trigger?
3) Syntax to DROP a trigger?
4) How to find total no of records in table?
5) Difference between Database and DBMS.

GVAIET/NBA-2013/CRITERIA 7.2/T-LP/CIVIL/SE/SEM III/LAB MANUAL/DBIR/REV.0/1.7.2016

Page 45

G.V.ACHARYA INSTITUTE OF ENGINEERING AND TECHNOLOGY, SHELU

GVAIET/NBA-2013/CRITERIA 7.2/T-LP/CIVIL/SE/SEM III/LAB MANUAL/DBIR/REV.0/1.7.2016

Page 46

G.V.ACHARYA INSTITUTE OF ENGINEERING AND TECHNOLOGY, SHELU

Ex. No. 7
NESTED SUBQUERIES
Date:
AIM:
To perform nested sub queries in book database.
QUERIES:
1. Find the books whose price is between 300 and 400
SQL> select * from books where price between 300 and 400;
2. Find the title, author name, stock quantity and price and pub year of the
books which are ordered.
SQL> select * from books b where exists(select * from orderlist o where
b.isbn=o.isbn);
3. Find the sum of the price of the books published in the year.
SQL> select sum(price) from books group by pubyear;
4. Find the sum of the price of the books published in the year and having price
>500
SQL> select sum(price),pubyear from books group by pubyear having
sum(price)>500;

5. Find the isbn of the books which may or may not ordered using union
operation
SQL> (select isbn from books)union(select isbn from orderlist);
6. Find the isbn of the books which are ordered using intersect operations
SQL> (select isbn from books)intersect(select isbn from orderlist);

GVAIET/NBA-2013/CRITERIA 7.2/T-LP/CIVIL/SE/SEM III/LAB MANUAL/DBIR/REV.0/1.7.2016

Page 47

G.V.ACHARYA INSTITUTE OF ENGINEERING AND TECHNOLOGY, SHELU

OUTPUT:

GVAIET/NBA-2013/CRITERIA 7.2/T-LP/CIVIL/SE/SEM III/LAB MANUAL/DBIR/REV.0/1.7.2016

Page 48

G.V.ACHARYA INSTITUTE OF ENGINEERING AND TECHNOLOGY, SHELU

GVAIET/NBA-2013/CRITERIA 7.2/T-LP/CIVIL/SE/SEM III/LAB MANUAL/DBIR/REV.0/1.7.2016

Page 49

G.V.ACHARYA INSTITUTE OF ENGINEERING AND TECHNOLOGY, SHELU

CONCLUSION:

Timely
Submission (5)

Presentation
(5)

Understanding (10)

Total (20)

Signature

VIVA QUESTIONS:
1) What is meant by nested query?
2) What is use of nested query?
3) Why Query?
4) What is foreign key?
5) Difference between primary key and foreign key.

GVAIET/NBA-2013/CRITERIA 7.2/T-LP/CIVIL/SE/SEM III/LAB MANUAL/DBIR/REV.0/1.7.2016

Page 50

G.V.ACHARYA INSTITUTE OF ENGINEERING AND TECHNOLOGY, SHELU

GVAIET/NBA-2013/CRITERIA 7.2/T-LP/CIVIL/SE/SEM III/LAB MANUAL/DBIR/REV.0/1.7.2016

Page 51

G.V.ACHARYA INSTITUTE OF ENGINEERING AND TECHNOLOGY, SHELU

Ex. No. 8
PL/SQL CURSOR
Date:
AIM :
To create PL/SQL cursor for payroll processing of an employee.
QUERIES:
SQL> create table empl(empno number(5),ename varchar(20),dob date,basicpay
number(5),da number(5),allowance number(5),tax number(5),lic number(5),grosspay
number(5));
Table created.
SQL> insert into empl
values(&empno,'&ename','&dob',&basicpay,&da,&allowance,&tax,&lic,&grosspay);
Enter value for empno: 101
Enter value for ename: siva
Enter value for dob: 01-aug-2000
Enter value for basicpay: 10000
Enter value for da: 4000
Enter value for allowance: 2000
Enter value for tax: 1000
Enter value for lic: 1200
Enter value for grosspay: 0
old 1: insert into empl
values(&empno,'&ename','&dob',&basicpay,&da,&allowance,&tax,&lic,&grosspay
new 1: insert into empl values(101,'siva','01-aug2000',10000,4000,2000,1000,1200,0)
1 row created.
SQL> select * from empl;
EMPNO ENAME DOB BASICPAY DA ALLOWANCE TAX LIC GROSSPAY
---------- ---------- ---------101
siva
01-AUG-00 10000 4000 2000
1000
1200
0
102

raja

11-MAR-01

20000 7000 3000

2000

2600

SQL> declare
2 cursor c is select * from empl order by grosspay desc;
3 rec empl % rowtype;
4 cnt integer:=0;
5 begin
6 open c;
7 loop
8 fetch c into rec;
GVAIET/NBA-2013/CRITERIA 7.2/T-LP/CIVIL/SE/SEM III/LAB MANUAL/DBIR/REV.0/1.7.2016

Page 52

G.V.ACHARYA INSTITUTE OF ENGINEERING AND TECHNOLOGY, SHELU

9 exit when c% notfound;


10 if(cnt<5) then
11 update empl set grosspay=(rec.basicpay+rec.da+rec.allowance)-(rec.lic+rec.tax)
where empno=rec.empno;
12 dbms_output.put_line('Employee no:'||rec.empno);
13 dbms_output.put_line('name:'||rec.ename);
14 dbms_output.put_line('Basic pay:'||rec.basicpay);
15 dbms_output.put_line('DA:'||rec.da);
16 dbms_output.put_line('allowance:'||rec.allowance);
17 dbms_output.put_line('Tax:'||rec.tax);
18 dbms_output.put_line('LIC:'||rec.lic);
19 dbms_output.put_line('Grosspay:'||rec.grosspay);
20 cnt:=cnt+1;
21 end if;
22 end loop;
23 close c;
24 end;
25 /
Employee no:101
name:siva
Basic pay:10000
DA:4000
allowance:2000
Tax:1000
LIC:1200
Grosspay:0
Employee no:102
name:raja
Basic pay:20000
DA:7000
allowance:3000
Tax:2000
LIC:2600
Grosspay:0
PL/SQL procedure successfully completed.
SQL> select * from empl;
EMPNO ENAME DOB BASICPAY DA ALLOWANCE TAX LIC GROSSPAY
---------- ---------- ---------101 siva 01-AUG-00
10000
4000
2000 1000
1200
13800
102 raja 11-MAR-01
20000
7000
3000 2000
2600
25400

CONCLUSION:
GVAIET/NBA-2013/CRITERIA 7.2/T-LP/CIVIL/SE/SEM III/LAB MANUAL/DBIR/REV.0/1.7.2016

Page 53

G.V.ACHARYA INSTITUTE OF ENGINEERING AND TECHNOLOGY, SHELU

imely
Submission
(5)

Presentation
(5)

Understanding
(10)

Total (20)

Signature

VIVA QUESTIONS:
1) What is cursor?
2) Why DBMS?
3) What is Query Language?
4) Difference between data and information.
5) What is database?

GVAIET/NBA-2013/CRITERIA 7.2/T-LP/CIVIL/SE/SEM III/LAB MANUAL/DBIR/REV.0/1.7.2016

Page 54

G.V.ACHARYA INSTITUTE OF ENGINEERING AND TECHNOLOGY, SHELU

GVAIET/NBA-2013/CRITERIA 7.2/T-LP/CIVIL/SE/SEM III/LAB MANUAL/DBIR/REV.0/1.7.2016

Page 55

G.V.ACHARYA INSTITUTE OF ENGINEERING AND TECHNOLOGY, SHELU

Ex. No. 9
VIEWS
Date:
AIM:
To create view for the bank database and do manipulation on that view.
QUERIES:
1. Create a view with the attributes accno,custid,balance,bname from the table
account.depositor
SQL> create view view1 as (select
account.accno,account.balance,depositer.custid,depositer.bname from
account,depositer where account.accno=depositer.accno);
View created.
SQL> select * from view1;
OUTPUT:

2. Create a view view2 with a all attributes from the table customer and
depositor
SQL> create view view2 as select c.custid,c.cname,c.address,d.accno,d.bname
from customer c,depositer d where c.custid=d.custid;
View created.
SQL> select * from view2;
OUTPUT:

GVAIET/NBA-2013/CRITERIA 7.2/T-LP/CIVIL/SE/SEM III/LAB MANUAL/DBIR/REV.0/1.7.2016

Page 56

G.V.ACHARYA INSTITUTE OF ENGINEERING AND TECHNOLOGY, SHELU

3. Create a View view3 for the employee residing at madurai


SQL> create view view3 as select * from emp1 where address='madurai';
View created.
SQL> select * from view3;
OUTPUT:

4. Insert a new record in view 3


SQL> insert into view3
values(&empno,'&empname','&address',&pay,'&qualification');
Enter value for empno: 120
Enter value for empname: sandeep
Enter value for address: sivakasi
Enter value for pay: 12000
Enter value for qualification: accountant
old 1: insert into view3
values(&empno,'&empname','&address',&pay,'&qualification')
new 1: insert into view3 values(120,'sandeep','sivakasi',12000,'accountant')
1 row created.
SQL> select * from view3;
OUTPUT:

GVAIET/NBA-2013/CRITERIA 7.2/T-LP/CIVIL/SE/SEM III/LAB MANUAL/DBIR/REV.0/1.7.2016

Page 57

G.V.ACHARYA INSTITUTE OF ENGINEERING AND TECHNOLOGY, SHELU

SQL> select * from emp1;


OUTPUT:

5. Update the branch name of the customer anu to AXIS CHN in view2.
SQL> update view2 set bname='AXIS CHN' where cname='anu';
1 row updated.
SQL> select * from view2;
OUTPUT:

GVAIET/NBA-2013/CRITERIA 7.2/T-LP/CIVIL/SE/SEM III/LAB MANUAL/DBIR/REV.0/1.7.2016

Page 58

G.V.ACHARYA INSTITUTE OF ENGINEERING AND TECHNOLOGY, SHELU

SQL> select * from depositer;


OUTPUT:

6. Delete the account no 30501 details from view1.


SQL> delete from view1 where accno=30501;
1 row deleted.
SQL> select * from view1;
OUTPUT:

GVAIET/NBA-2013/CRITERIA 7.2/T-LP/CIVIL/SE/SEM III/LAB MANUAL/DBIR/REV.0/1.7.2016

Page 59

G.V.ACHARYA INSTITUTE OF ENGINEERING AND TECHNOLOGY, SHELU

SQL> select * from depositer;


OUTPUT:

CONCLUSION:
GVAIET/NBA-2013/CRITERIA 7.2/T-LP/CIVIL/SE/SEM III/LAB MANUAL/DBIR/REV.0/1.7.2016

Page 60

G.V.ACHARYA INSTITUTE OF ENGINEERING AND TECHNOLOGY, SHELU

Timely
Submission (5)

Presentation
(5)

Understanding (10)

Total (20)

Signature

VIVA QUESTIONS:
1) What is a view in DBMS?
2) State different types of views.
3) How to create views?
4) What is the use of views?
5) How to create views?

GVAIET/NBA-2013/CRITERIA 7.2/T-LP/CIVIL/SE/SEM III/LAB MANUAL/DBIR/REV.0/1.7.2016

Page 61

G.V.ACHARYA INSTITUTE OF ENGINEERING AND TECHNOLOGY, SHELU

Ex. No. 10
Date:

MENU DRIVEN APPLICATION USING VB

GVAIET/NBA-2013/CRITERIA 7.2/T-LP/CIVIL/SE/SEM III/LAB MANUAL/DBIR/REV.0/1.7.2016

Page 62

G.V.ACHARYA INSTITUTE OF ENGINEERING AND TECHNOLOGY, SHELU

AIM:
To Access and manipulate database through visual basic.
PROCEDURE:

Click Start-> Settings-> Control panel.


Select Administrative tools -> Data sources(ODBC).
Click Add -> Select Microsoft ODBC for oracle -> Finish.
Click Program -> Microsoft Visual studio -> Select Visual studio basic
6.0
In this select standard project and Click Open.
In the form we can design using labels and Text boxes.
Find Select Project-> Components.
Select Microsoft ADO data control 6.0(OLE DB) and Click Apply.
Drag the ADODC and place in the form.
ADODC-> Properties -> Connection string-> Built.
In this Select Microsoft OLE DB provider for OLDBC driver -> Click
Next.
Give the table name in data source name and also give username and
password -> Click test connection -> Ok -> Apply.
Click Authentication -> Username, Password.
Click Record source -> Odcmd table -> Select the table name (EMP2)
-> Ok.
Set the textbox Property as Data Source -> Right click -> ADODC.
Data field -> <Column name> (empid)
Click project -> ADD MDI FORM.
MDI form will be displayed.
In this right click and select menu & editor create FORM & REPORT
Menu.
Click Project -> select Project1 Properties.
Set Startup Project as MDI form.
Set the form1 and report as child for MDI form by Form1 -> Properties> MDI child -> True.
Click Project- > Components->Designer select Data environment &
Data report -> Click apply ->Ok
Click Project->Data environment -> Connection1 right click select
properties right click select properties right click select ADD cmd
Click project -> Data report -> Add data report -> Add Data report
Data report properties set
Data source -> Data environment
Data member -> Command

GVAIET/NBA-2013/CRITERIA 7.2/T-LP/CIVIL/SE/SEM III/LAB MANUAL/DBIR/REV.0/1.7.2016

Page 63

G.V.ACHARYA INSTITUTE OF ENGINEERING AND TECHNOLOGY, SHELU

In MDI form set the text box properties data members


Write the coding for each and every buttons
Run the project.
CODING:
ADD:
Private sub commands_click()
Adodc1.Recordset.Addnew
End sub
EDIT:
Private sub commands_click()
Adodc1.Recordset.Update
End sub
CLEAR:
Private sub commands_click()
Text1.text=
Text2.text=
Text3.text=
End sub
DELETE:
Private sub commands_click()
Adodc1.Recordset.Delete
End sub
FIRST:
Private sub commands_click()
Adodc1.Recordset.Move first
End sub
LAST:
Private sub commands_click()
Adodc1.Recordset.Move last
End sub
NEXT:
Private sub commands_click()
Adodc1.Recordset.Move next
End sub
PREVIOUS:
Private sub commands_click()
Adodc1.Recordset.Move previous
End sub
FORM:
Private sub mnu_depart_click()
Form1.show
End sub
REPORT:
GVAIET/NBA-2013/CRITERIA 7.2/T-LP/CIVIL/SE/SEM III/LAB MANUAL/DBIR/REV.0/1.7.2016

Page 64

G.V.ACHARYA INSTITUTE OF ENGINEERING AND TECHNOLOGY, SHELU

Private sub-mnu employee_click()


Data report1.show
End sub
OUTPUT:

GVAIET/NBA-2013/CRITERIA 7.2/T-LP/CIVIL/SE/SEM III/LAB MANUAL/DBIR/REV.0/1.7.2016

Page 65

G.V.ACHARYA INSTITUTE OF ENGINEERING AND TECHNOLOGY, SHELU

GVAIET/NBA-2013/CRITERIA 7.2/T-LP/CIVIL/SE/SEM III/LAB MANUAL/DBIR/REV.0/1.7.2016

Page 66

G.V.ACHARYA INSTITUTE OF ENGINEERING AND TECHNOLOGY, SHELU

GVAIET/NBA-2013/CRITERIA 7.2/T-LP/CIVIL/SE/SEM III/LAB MANUAL/DBIR/REV.0/1.7.2016

Page 67

G.V.ACHARYA INSTITUTE OF ENGINEERING AND TECHNOLOGY, SHELU

CONCLUSION:

GVAIET/NBA-2013/CRITERIA 7.2/T-LP/CIVIL/SE/SEM III/LAB MANUAL/DBIR/REV.0/1.7.2016

Page 68

G.V.ACHARYA INSTITUTE OF ENGINEERING AND TECHNOLOGY, SHELU

Timely
Submission (5)

Presentation
(5)

Understanding (10)

Total (20)

Signature

VIVA QUESTIONS:
1) What is Visual Basic 6.0?
2) What is ODBC?
3) What are features of visual Basic 6.0?
4) What is GUI?
5) What is use of GUI?

GVAIET/NBA-2013/CRITERIA 7.2/T-LP/CIVIL/SE/SEM III/LAB MANUAL/DBIR/REV.0/1.7.2016

Page 69

G.V.ACHARYA INSTITUTE OF ENGINEERING AND TECHNOLOGY, SHELU

GVAIET/NBA-2013/CRITERIA 7.2/T-LP/CIVIL/SE/SEM III/LAB MANUAL/DBIR/REV.0/1.7.2016

Page 70

Das könnte Ihnen auch gefallen