Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Advanced Databases Laboratory-CP7211

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 61

INDEX

S.NO DATE CONTENT PAGE NO SIGN

IMPLEMENTATION DISTRIBUTED
1 DATABASE-BOOK STORE APPLICATION

IMPLEMENTATION OF DEADLOCK
2 DEDUCTION ALGORITHM FOR
DISTRIBUTED DATABASE

IMPLEMENTATION OF OBJECT ORIENTED


3 DATABASE-UNIVERSITY APPLICATION

IMPLEMENTATION OF PARALLEL
4 DATABASE-UNIVERSITY COUNSELLING
APPLICATION

IMPLEMENTATION OF PARALLEL
5 DATABASE-UNIVERSITY COLLEGE MARK
SYSTEM APPLICATION

ACTIVE DATABASE-CREATION OF
6 TRIGGERS AND ASSERTIONS FOR BANK
DATABASE

IMPLEMENTATION OF DEDUCTIVE
7 DATABASE-KINSHIP DOMAIN
APPLICATION

CLASSIFICATION AND CLUSTERING OF


8 TRAINING DATA USING WEKA TOOL

9 IMPLEMENTATION OF QUERY OPTIMIZER

DESIGNING XML SCHEMA FOR COMPANY


10 DATABASE
EX.NO: 01 IMPLEMENTATION DISTRIBUTED DATABASE
-BOOK STORE APPLICATION

AIM:

To Consider a distributed database for a bookstore with 4 sites called S1, S2, S3 and S4.
Consider the following relations:
Books ( ISBN, primary Author, topic, total Stock, price )
Book Store (store No, city, state, zip, inventoryValue )
Stock (store No, ISBN, Qty )
Total Stock is the total number of books in stock and inventory Value is the total inventory value
for the store in dollars.
Consider that Books are fragmented by price amounts into:
F1: Books: price up to $20
F2: Books: price from $20.01 to $50
F3: Books: price from $50.01 to $100
F4: Books: price $100.01 and above
Similarly, Book Stores are divided by ZIP codes into:
S1: Bookstore: Zip up to 25000
S2: Bookstore: Zip 25001 to 50000
S3: Bookstore: Zip 50001 to 75000
S4: Bookstore: Zip 75001 to 99999
Task: Write SQL query for the following
1. Insert and Display details in each table.
2. Find the total number of books in stock where price is between $15 & $55.
3. Update the book price of book No=1234 from $45 to $55 at site S3.
4. Find total number of book at site S2.
PROCEDURE:

Books ( ISBN, primary Author, topic, total Stock, price )

SQL> create table books


(
ISBN int not null,
pri_author varchar(40),
topic varchar(50),
tot_stock int,
price float,
storeno int,
constraint fk_storeno1 foreign key(storeno)
references bookstores(storeno),
primary key(ISBN)
)
PARTITION BY RANGE (price)
(
PARTITION F1 values less than (20.1),
PARTITION F2 values less than (50.1),
PARTITION F3 values less than (100.01),
PARTITION F4 VALUES LESS THAN (MAXVALUE)
);
Table created.

SQL> insert into books values('1234','elmasri','dbms','50','15.02','12');


1 row created.
SQL> insert into books values('5678','kruse','nis','14','17.99','23');
1 row created.
SQL> insert into books values('2345','silberchatz','os','30','45','34');
1 row created.
SQL> insert into books values('3456','veeraSACOEn','maths','25','51','45');
1 row created.
SQL> insert into books values('4567','william','networks','10','62.66','56');
1 row created.
SQL> insert into books values('5678','kruse','nis','14','17.99','23');
1 row created.
SQL> insert into books values ('6789','vijaya','discrete','20','188.99','67');
1 row created.
SQL> insert into books values ('7896','karl','wsn1','35','25.55','89');
1 row created.
SQL> select * from books;

ISBN P_AUTHOR TOPIC TOTAL_STOCK PRICE STORENO


--------------------------------------------------------------------------------------------
1234 elmasri dbms 50 15.02 12
5678 kruse nis 14 17.99 23
2345 silberchatz os 30 45 34
7896 karl wsn1 35 25.55 89
3456 veeraSACOEn maths 25 51 45
4567 william networks 10 62.66 56
7889 holger wsn 25 56.76 78
6789 vijaya discrete 20 188.99 67

8 rows selected.

SQL> select * from books partition(F1);

ISBN P_AUTHOR TOPIC TOTAL_STOCK PRICE STORENO


--------------------------------------------------------------------------------------------
1234 elmasri dbms 50 15.02 12
5678 kruse nis 14 17.99 23

SQL> select * from books partition(F2);

ISBN P_AUTHOR TOPIC TOTAL_STOCK PRICE STORENO


--------------------------------------------------------------------------------------------
2345 silberchatz os 30 34 34
7896 karl wsn1 35 25.55 89

SQL> select * from books partition(F3);

ISBN P_AUTHOR TOPIC TOTAL_STOCK PRICE STORENO


--------------------------------------------------------------------------------------------
3456 veeraSACOEn maths 25 51 45
4567 william networks 10 62.66 56
7889 holger wsn 25 56.76 78

SQL> select * from books partition(F4);

ISBN P_AUTHOR TOPIC TOTAL_STOCK PRICE STORENO


--------------------------------------------------------------------------------------------
6789 vijaya discrete 20 188.99 67
Book Store (store No, city, state, zip, inventory Value)
SQL> create table bookstore
(
storeno int not null,
city varchar(30),
state varchar(30),
zip int,
inventval varchar(10),
primary key(storeno)
)
PARTITION BY RANGE (zip)
(
PARTITION S1 values less than (25000),
PARTITION S2 values less than (50000),
PARTITION S3 values less than (75000),
PARTITION S4 values less than (99999)
);
Table created.

SQL> insert into bookstore values('12','Dindigul','TamilNadu','24950','DG111');


1 row created.
SQL> insert into bookstore values('23','Mysore','Karnataka','35000','KA222');
1 row created.
SQL> insert into bookstore values('34','Cochin','Kerala','71340','KL333');
1 row created.
SQL> insert into bookstore values('45','Hyderabad','Andhra','88000','AP444');
1 row created.
SQL> insert into bookstore values('56','Pune','Mumbai','20000','MH555');
1 row created.
SQL> insert into bookstore values('67','Chennai','TamilNadu','75000','TN666');
1 row created.
SQL> insert into bookstore values('78','Lucknow','UP','90000','UP777');
1 row created.
SQL> insert into bookstore values('89','Westbengal','Kolkata','45000','WE888');
1 row created.

SQL> select * from bookstore;

STORENO CITY STATE ZIP INVAL


---------- ---------- ---------- ---------- ----------------------
12 Dindigul TamilNadu 24950 DG111
56 Pune Mumbai 20000 MH555
23 Mysore Karnataka 35000 KA222
89 Westbengal Kolkata 45000 WE888
34 Cochin Kerala 71340 KL333
45 Hyderabad Andhra 88000 AP444
67 Chennai TamilNadu 75000 TN666
78 Lucknow UP 90000 UP777
8 rows selected.
SQL> select * from bookstore partition(S1);

STORENO CITY STATE ZIP INVAL


---------- ---------- ---------- ---------- ----------------------------
12 Dindigul TamilNadu 24950 DG111
56 Pune Mumbai 20000 MH555

SQL> select * from bookstore partition(S2);

STORENO CITY STATE ZIP INVAL


---------- ---------- ---------- ---------- ---------------------------
23 Mysore Karnataka 35000 KA222
89 Westbengal Kolkata 45000 WE888

SQL> select * from bookstore partition(S3);

STORENO CITY STATE ZIP INVAL


---------- ---------- ---------- ---------- ---------------------------
34 Cochin Kerala 71340 KL333

SQL> select * from bookstore partition(S4);

STORENO CITY STATE ZIP INVAL


---------- ---------- ---------- ---------- ----------------------------
45 Hyderabad Andhra 88000 AP444
67 Chennai TamilNadu 75000 TN666
78 Lucknow UP 90000 UP777
Stock (store No, ISBN, Qty )
SQL> create table stock
(
storeno int,
ISBN int,
qty varchar(10)
);
Table created.

SQL> insert into stock select ISBN,total_stock as qty, storeno from books1;

ISBN QTY STORE NO


----------------------------------------------
1234 50 12
5678 14 23
2345 30 34
7896 35 89
3456 25 45
4567 10 56
7889 25 78
6789 20 67
2. SQL> select sum(qty) from stock where storeno in (select storeno from books1 where price
between 15 and 55);

SUM(QTY)
---------
154

3.SQL> update books1 partition(f3) set price=55 where storeno in(select storeno from bookstore
where zip in(select zip from bookstore partition(s4)));

2 rows updated.

SQL> select * from books;

ISBN P_AUTHOR TOPIC TOTAL_STOCK PRICE STORENO


---------- --------------- --------------- ----------- ---------- ----------------------------------------
1234 elmasri dbms 50 15.02 12
5678 kruse nis 14 17.99 23
2345 silberchatz os 30 45 34
7896 karl wsn1 35 25.55 89
3456 veeraSACOEn maths 25 55 45
4567 william networks 10 62.66 56
7889 holger wsn 25 55 78
6789 vijaya discrete 20 188.99 67

8 rows selected.

4.SQL> select sum(qty)as totalbooks from stock where storeno in(select storeno from bookstore
where zip in(select zip from bookstore partition(s2)));

TOTALBOOKS
-------------------
49

RESULT:
Thus a distributed database for a bookstore with 4 sites called S1, S2, S3
and S4 was created successfully.
EX.NO: 02 IMPLEMENTATION OF DEADLOCK DEDUCTION
ALGORITHM FOR DISTRIBUTED DATABASE

AIM:

To implement Deadlock Detection Algorithm for Distributed Database using Wait-for


Graph to check for Deadlock.

PROCEDURE:

There are five transactions T1, T2, T3, T4 and T5 with


 T1 initiated at site S1 and spawning an agent at site S2
 T2 initiated at site S3 and spawning an agent at site S1
 T3 initiated at site S1 and spawning an agent at site S3
 T4 initiated at site S2 and spawning an agent at site S3
 T5 initiated at site S3

Wait For Graph:


CODINGS:

SQL> DD1 :
declare
cursor c1 is
SELECT trans, loc, wait
FROM dd1;
type c_list is varray(20) of dd1.loc%type;
ll c_list:=c_list();
type c_list1 is varray(20) of dd1.wait%type;
l2 c_list1:=c_list1();
type c_list2 is varray(20) of dd1.trans%type;
t c_list:=c_list();
c integer := 0;
d integer :=0;
f integer :=0;
ss c1%rowtype;
begin
open c1;
dbms_output.put_line('TRANS '||' '||'Lock'||' '||'wait');
loop
fetch c1 into ss;
exit when c1%notfound;
c := c+1;
ll.extend;
ll(c) := ss.loc;
f := f+1;
t.extend;
t(f) := ss.trans;
d :=d+1;
l2.extend;
l2(d) := ss.wait;
dbms_output.put_line(ss.trans||' '||ss.loc||' '||ss.wait);
end loop;
for i in 1 .. c loop
for j in 1 .. d loop
if ( ll(i) = l2(j)) then
if(ll(i) != '-')then
dbms_output.put_line(ll(i)||'<-'||l2(j)||'deadlock occured');
end if;
end if;
end loop;
end loop;
end;

SQL>DD2:
declare
cursor c1 is
SELECT trans, loc, wait
FROM dd1
WHERE Site='s1';
type c_list is varray(10) of dd1.loc%type;
ll c_list:=c_list();
type c_list1 is varray(10) of dd1.wait%type;
l2 c_list1:=c_list1();
type c_list2 is varray(20) of dd1.trans%type;
t c_list:=c_list();
c integer := 0;
d integer :=0;
ss c1%rowtype;
begin
open c1;
dbms_output.put_line('TRANS '||' '||'Lock'||' '||'wait');
loop
fetch c1 into ss;
exit when c1%notfound;
dbms_output.put_line(ss.trans||' '||ss.loc||' '||ss.wait);
c := c+1;
ll.extend;
ll(c) := ss.loc;
d :=d+1;
l2.extend;
l2(d) := ss.wait;
end loop;
for i in 1 .. c loop
for j in 1 .. d loop
if ( ll(i) = l2(j)) then
dbms_output.put_line(ll(i)||'<-'||l2(j)||'deadlock occured');
end if;
end loop;
end loop;
end;

SQL>DD3:
declare
cursor c1 is
SELECT trans, loc, wait
FROM dd1
WHERE Site='s2';
type c_list is varray(10) of dd1.loc%type;
ll c_list:=c_list();
type c_list1 is varray(10) of dd1.wait%type;
l2 c_list1:=c_list1();
type c_list2 is varray(20) of dd1.trans%type;
t c_list:=c_list();
c integer := 0;
d integer :=0;
e integer :=0;
ss c1%rowtype;
begin
open c1;
dbms_output.put_line('TRANS '||' '||'Lock'||' '||'wait');
loop
fetch c1 into ss;
exit when c1%notfound;
dbms_output.put_line(ss.trans||' '||ss.loc||' '||ss.wait);
c := c+1;
ll.extend;
ll(c) := ss.loc;
d :=d+1;
l2.extend;
l2(d) := ss.wait;
end loop;
for i in 1 .. c loop
for j in 1 .. d loop
if ( ll(i) = l2(j)) then
dbms_output.put_line(ll(i)||'<-'||l2(j)||'deadlock occured');
end if;
end loop;
end loop;
if (e = 0) then
dbms_output.put_line('no deadlock ');
end if;
end;
SQL>DD4:
declare
cursor c1 is
SELECT trans, loc, wait
FROM dd1
WHERE Site='s3';
type c_list is varray(10) of dd1.loc%type;
ll c_list:=c_list();
type c_list1 is varray(10) of dd1.wait%type;
l2 c_list1:=c_list1();
type c_list2 is varray(20) of dd1.trans%type;
t c_list:=c_list();
c integer := 0;
d integer :=0;
ss c1%rowtype;
begin
open c1;
dbms_output.put_line('TRANS '||' '||'Lock'||' '||'wait');
loop
fetch c1 into ss;
exit when c1%notfound;
dbms_output.put_line(ss.trans||' '||ss.loc||' '||ss.wait);
c := c+1;
ll.extend;
ll(c) := ss.loc;
d :=d+1;
l2.extend;
l2(d) := ss.wait;
end loop;
for i in 1 .. c loop
for j in 1 .. d loop
if ( ll(i) = l2(j)) then
dbms_output.put_line(ll(i)||'<-'||l2(j)||'deadlock occured');
end if;
end loop;

SQL> create table dd1(trans varchar(20),loc varchar2(10),wait varchar2(10),site varchar2(10));


Table created.

SQL> insert into dd1 values('t1','x1','x8','s1');


1 row created.
SQL> insert into dd1 values('t1','x6','x2','s2');
1 row created.
SQL> insert into dd1 values('t2','x4','x7','s2');
1 row created.
SQL> insert into dd1 values('t2','x5',' ','s3');
1 row created.
SQL> insert into dd1 values('t3','x2','x7','s1');
1 row created.
SQL> insert into dd1 values('t4','x7',' ','s2');
1 row created.
SQL> insert into dd1 values('t4','x8','x5','s3');
1 row created.
SQL> insert into dd1 values('t5','x3','x7','s3');
1 row created.
SQL> select * from dd1;
TRANS LOC WAIT SITE
-------------------- ---------- ---------- ----------
t1 x1 x8 s1
t1 x6 x2 s2
t2 x4 x7 s2
t2 x5 s3
t3 x2 x7 s1
t4 x7 s2
t4 x8 x5 s3
t5 x3 x7 s3
8 rows selected.
SQL> ed dd1;
SQL> set serveroutput on;
SQL> @dd1;
SQL> ed dd1;
SQL> @dd1;
42 /
ll(c) := ss.lock1;
SQL> ed dd1;
SQL> @dd1;
42 /
TRANS LOCK WAIT
t1 x1 x8
t1 x6 x2
t2 x4 x7
t2 x5
t3 x2 x7
t4 x7
t4 x8 x5
t5 x3 x7
x5<-x5deadlock occured
x2<-x2deadlock occured
x7<-x7deadlock occured
x7<-x7deadlock occured
x7<-x7deadlock occured
x8<-x8deadlock occured
PL/SQL procedure successfully completed.
SQL> ed dd2;
SQL> @dd2;
37 /
TRANS LOCK WAIT
t1 x1 x8
t3 x2 x7

PL/SQL procedure successfully completed.

SQL> ed dd3;
SQL> ed dd3;
SQL> @dd3;
41 /
TRANS LOCK WAIT
t1 x6 x2
t2 x4 x7
t4 x7
x7<-x7deadlock occured
no deadlock

PL/SQL procedure successfully completed.

SQL> ed dd4;
SQL> @dd4;
37 /
TRANS LOCK WAIT
t2 x5
t4 x8 x5
t5 x3 x7
x5<-x5deadlock occured

PL/SQL procedure successfully completed.


SQL> ed dd1;
SQL> @dd1;
42 /
TRANS LOCK WAIT
t1 x1 x8
t1 x6 x2
t2 x4 x7
t2 x5
t3 x2 x7
t4 x7
t4 x8 x5
t5 x3 x7
x5<-x5deadlock occured
x2<-x2deadlock occured
x7<-x7deadlock occured
x7<-x7deadlock occured
x7<-x7deadlock occured
x8<-x8deadlock occured

PL/SQL procedure successfully completed.


RESULT:
Thus the Deadlock Detection Algorithm Distributed Database has been developed and
executed successfully.

EX.NO: 03 IMPLEMENTATION OF OBJECT ORIENTED


DATABASE -UNIVERSITY APPLICATION
AIM:

To design an Enhanced Entity Relationship model for University database and to write Object
Query Language (OQL) to manage the database.

SQL Query:
Creation and insertion use University go
------------------------------------------------------------------------------
----------Design and create the tables needed
---------------------------------------------------------------------------
create table department
(
DeptID int identity(1,1) PRIMARY KEY,
DeptName varchar(10)
)

go
create table dbo.Roles
(
RoleID int not null identity(1,1) PRIMARY KEY,
RoleName varchar(30) not null
)
go
create table dbo.Gender
(
GenderID int not null identity(1,1) PRIMARY KEY,
Gender varchar(10) not null
)
go
create table dbo.StatusTable
(
ID int NOT NULL PRIMARY KEY,
[Status] varchar(10)
)
go
create table dbo.Users
(
UserID int NOT NULL identity(1,1) PRIMARY KEY,
UserName varchar(30),
[Address] varchar(100),
Phone varchar(20),
DeptID int FOREIGN KEY REFERENCES department(DeptID),
Gender int FOREIGN KEY REFERENCES Gender(GenderID),
RoleId int FOREIGN KEY REFERENCES Roles(RoleID),
SubRoleID int FOREIGN KEY REFERENCES SubRoles(SubRoleID),
StatusId int FOREIGN KEY REFERENCES StatusTable(ID)
)
go
create table dbo.SubRoles
(
SubRoleID int identity(1,1) PRIMARY KEY,
RoleID int FOREIGN KEY REFERENCES Roles(RoleID),
SubRoleName varchar(30)
)
go
----------------------------------------------------------------------
--------Insert Values into the tables----------------------------
-------------------------------------------------------------------
insert into dbo.department
values('CSE')
go
insert into dbo.department
values('IT')
go
insert into dbo.department
values('ECE')
go
insert into dbo.Roles
values('Employee')
go
insert into dbo.Roles
values('Student')
go
insert into dbo.Gender
values('Male')
go
insert into dbo.Gender
values('Female')
go
insert into dbo.StatusTable
values(1,'Active')
go
insert into dbo.StatusTable
values(2,'InActive')
go
insert into dbo.SubRoles
values(1,'Faculty')
go
insert into dbo.SubRoles
values(1,'Technicians')
go
insert into dbo.SubRoles
values(1,'Project associates')
go
insert into dbo.SubRoles
values(2,'Full Time')
go
insert into dbo.SubRoles
values(2,'Part Time')
go
insert into dbo.SubRoles
values(2,'Teaching Assistant')
go
insert into users values
('kalpana','2-Richie street, chennai',9840000000,1,2,2,2,1)

--ii. Display the Employee details


--a. Display General Employee details :
select
Username as [EmployeeName],
[Address] as [Address],
Phone as [Contact],
d.DeptName as [Department],
g.Gender as [Gender],
s.SubRoleName as [ROle],
st.Status as [Status]
 from users u
inner join department d on d.DeptID = u.DeptID
inner join Gender g on g.GenderID = u.Gender
inner join SubRoles s on s.SubRoleID = u.SubRoleID
inner join StatusTable st on st.ID = u.StatusID
where u.RoleID = 1 --(Employee Role is filtered)

--b. Display Female Employee Details


select
Username as [EmployeeName],
[Address] as [Address],
Phone as [Contact],
d.DeptName as [Department],
g.Gender as [Gender],
s.SubRoleName as [ROle],
st.Status as [Status]
 from users u
inner join department d on d.DeptID = u.DeptID
inner join Gender g on g.GenderID = u.Gender
inner join SubRoles s on s.SubRoleID = u.SubRoleID
inner join StatusTable st on st.ID = u.StatusID
where u.RoleID = 1 and u.Gender = 2 --(Employee Role and female gender
- filtered)

--iii. Display Student Details.


--a.Select General Student Details
select
Username as [EmployeeName],
[Address] as [Address],
Phone as [Contact],
d.DeptName as [Department],
g.Gender as [Gender],
s.SubRoleName as [ROle],
st.Status as [Status]
 from users u
inner join department d on d.DeptID = u.DeptID
inner join Gender g on g.GenderID = u.Gender
inner join SubRoles s on s.SubRoleID = u.SubRoleID
inner join StatusTable st on st.ID = u.StatusID
where u.RoleID = 2 --(Student Role is filtered)

--b.Display only full time students


select
Username as [EmployeeName],
[Address] as [Address],
Phone as [Contact],
d.DeptName as [Department],
g.Gender as [Gender],
s.SubRoleName as [ROle],
st.Status as [Status]
 from users u
inner join department d on d.DeptID = u.DeptID
inner join Gender g on g.GenderID = u.Gender
inner join SubRoles s on s.SubRoleID = u.SubRoleID
inner join StatusTable st on st.ID = u.StatusID
where u.RoleID = 2 and u.SubRoleID = 4--(Student Role and Full-time
SubRole - filtered)

iv Modify User details


v) Delete User details
--vi) Modify Person details
--a.Update Phone number of a user
Update Users
set Phone = 9840202000
where userid = 1

--b.Update all the part time students as full time students and all
the full time students
--as part time students
Update Users
set SubRoleID = Case when SubRoleID = 4 then 5
                     when SubRoleID = 5 then 4
where SubRoleID in (4,5) --This condition avoids the control to check
in all the rows

v. Delete Person Details


a)Delete an User from the table
Delete from Users
where UserID = 2
b)Delete users if their status is inactive
Delete from users
where StatusID = 2

RESULT:
Thus the Object Oriented Database for Extended Entity Relationship (EER) has
been developed and executed successfully.
DATE: IMPLEMENTATION OF PARALLEL DATABASE-
EX.NO: 04 UNIVERSITY COUNSELLING APPLICATION
PROBLEM STATEMENT:

Consider the application for University Counseling for Engineering Colleges. The college,
department and vacancy details are maintained in 3 sites. Students are allocated colleges in these 3
sites simultaneously. Implement this application using parallel database.

AIM:

To create an application for University Counseling for Engineering college using


parallel database using Oracle.

Software Required:

• SQL Plus
• Oracle 9i

SQL statements for the Application:


Table Create Statement For table_site1:

SQL> CREATE TABLE table_site1


(
collegeID int NOT NULL,
collegeName varchar(50) NOT NULL,
Department varchar(30) NOT NULL,
vacancy int,
CONSTRAINT college_pk PRIMARY KEY (collegeID)
);

Table created.

Table Create Statement For table_site2:

SQL> CREATE TABLE table_site2


(
collegeID int NOT NULL,
collegeName varchar(50),
Department varchar(30),
vacancy int,
CONSTRAINT fk_site1
FOREIGN KEY (collegeID)
REFERENCES table_site1(collegeID)
ON DELETE CASCADE
);

Table created.
Table Create Statement For table_site3:

SQL> CREATE TABLE table_site3


(
collegeID int,
collegeName varchar(50),
Department varchar(30),
vacancy int,
CONSTRAINT fk_site1_2
FOREIGN KEY (collegeID)
REFERENCES table_site1(collegeID)
ON DELETE CASCADE
);

Table created.
Trigger Statement For Automatic Updation in site2 & site3:

SQL> CREATE or REPLACE TRIGGER trigger_Updatetable


AFTER UPDATE
ON table_site1
FOR EACH ROW
BEGIN
UPDATE table_site2 a
SET a.vacancy = a.vacancy-1 where a.collegeName=:old.collegeName AND a.Department =
:old.Department;
UPDATE table_site3 b
SET b.vacancy = vacancy-1 where b.collegeName=:old.collegeName AND b.Department=
:old.Department;
END;
/
Trigger created.
Trigger Statement For Insertion in site2 & site3:

SQL> CREATE or REPLACE TRIGGER trigger_inserttable


AFTER INSERT
ON table_site1
FOR EACH ROW
BEGIN
INSERT INTO table_site2 (collegeID,collegeName,Department,vacancy) VALUES
(:NEW.collegeID,:NEW.collegeName,:NEW.Department,:NEW.vacancy);
INSERT INTO table_site3 (collegeID,collegeName,Department,vacancy) VALUES
(:NEW.collegeID,:NEW.collegeName,:NEW.Department,:NEW.vacancy);
END;
/
Trigger created.
Insertion Statements For table_site1:

SQL> INSERT INTO table_site1 VALUES(1,'VV College of Engineering','CSE',30);


1 row created.
SQL> INSERT INTO table_site1 VALUES(2,'Dr.Sivanthi Aditanar College of Engineering',
'CSE',30);
1 row created.
SQL> INSERT INTO table_site1 VALUES(3,'National Engineering College','CSE',30);
1 row created.
SQL> INSERT INTO table_site1 VALUES(4,'Holy Cross Engineering College','CSE',30);
1 row created.
SQL> INSERT INTO table_site1 VALUES(5,'National College of Engineering','CSE',30);
1 row created.
SQL> INSERT INTO table_site1 VALUES(6,’Sun Engineering College','CSE',30);
1 row created.
SQL> INSERT INTO table_site1 VALUES(7,'VV College of Engineering','ECE',30);
1 row created.
SQL> INSERT INTO table_site1 VALUES(8,'Dr.Sivanthi Aditanar College of
Engineering','ECE',30);
1 row created.
SQL> INSERT INTO table_site1 VALUES(9,'National Engineering College','ECE',30);
1 row created.
SQL> INSERT INTO table_site1 VALUES(10,'Holy Cross Engineering College','ECE',30);
1 row created.
SQL> INSERT INTO table_site1 VALUES(11,'National College of Engineering','ECE',30);
1 row created.
SQL> INSERT INTO table_site1 VALUES(12, 'Sun Engineering College','ECE',30);
1 row created.

Select Statements in table_site1, table_site2, table_site3:

SQL> select * from table_site1;


COLLEGEID COLLEGENAME DEPARTMENT VACANCY
1 VV College of Engineering CSE 30
2 Dr.Sivanthi Aditanar College of CSE 30
Engineering
3 National Engineering College CSE 30
4 Holy Cross Engineering College CSE 30
5 National College of Engineering CSE 30
6 Sun Engineering College CSE 30
7 VV College of Engineering ECE 30
8 Dr.Sivanthi Aditanar College of ECE 30
Engineering
9 National Engineering College ECE 30
10 Holy Cross Engineering College ECE 30
11 National College of Engineering ECE 30
12 Sun Engineering College ECE 30

12 rows selected.
SQL> select * from table_site2;
COLLEGEID COLLEGENAME DEPARTMENT VACANCY
1 VV College of Engineering CSE 30
2 Dr.Sivanthi Aditanar College of CSE 30
Engineering
3 National Engineering College CSE 30
4 Holy Cross Engineering College CSE 30
5 National College of Engineering CSE 30
6 Sun Engineering College CSE 30
7 VV College of Engineering ECE 30
8 Dr.Sivanthi Aditanar College of ECE 30
Engineering
9 National Engineering College ECE 30
10 Holy Cross Engineering College ECE 30
11 National College of Engineering ECE 30
12 Sun Engineering College ECE 30

12 rows selected.

SQL> select * from table_site3;


COLLEGEID COLLEGENAME DEPARTMENT VACANCY
1 VV College of Engineering CSE 30
2 Dr.Sivanthi Aditanar College of CSE 30
Engineering
3 National Engineering College CSE 30
4 Holy Cross Engineering College CSE 30
5 National College of Engineering CSE 30
6 Sun Engineering College CSE 30
7 VV College of Engineering ECE 30
8 Dr.Sivanthi Aditanar College of ECE 30
Engineering
9 National Engineering College ECE 30
10 Holy Cross Engineering College ECE 30
11 National College of Engineering ECE 30
12 Sun Engineering College ECE 30
12 rows selected.
Update a College Vacancy when the college seat is selected:

SQL> UPDATE table_site1 SET vacancy=vacancy-1 where collegeName='National College of


Engineering' AND Department='CSE';

1 row updated.

Select Statements using parallel keyword:

SQL > select /*+parallel*/ * from table_site2 where collegeName='National College of


Engineering' ;

COLLEGEID COLLEGENAME DEPARTMENT VACANCY


---------- -------------------------------------------------- -------------------------------------- ----------
5 National College of Engineering CSE 29
11 National College of Engineering ECE 30

SQL> select /*+ parallel */ sum(vacancy) from table_site1 where Department='CSE';

SUM(VACANCY)
-----------------------
179

SQL> select /*+ parallel */ DISTINCT collegeName FROM table_site1;

COLLEGENAME
--------------------------------------------------
VV College of Information Technology
VV College of Engineering
National Engineering College
Holy Cross Engineering College
National College of Engineering
Dr.Sivanthi Aditanar College of Engineering

6 rows selected.

SQL> select /*+ parallel */ DISTINCT Department FROM table_site1;

DEPARTMENT
----------------------
CSE
ECE

RESULT:

The College Counseling application was implemented using parallel database successfully.
EX.NO: 05 IMPLEMENTATION OF PARALLEL DATABASE-
UNIVERSITY COLLEGE MARK SYSTEM APPLICATION

PROBLEM STATEMENT:

There are 5 processors working in a parallel environment and producing output. The
output record contains college details and student mark information. Implement parallel join and
parallel sort algorithm to get the marks from different colleges of the university and publish 10
ranks for each discipline.

AIM:

To implement parallel join and parallel sort algorithms to get the marks from different
colleges of the university and publish 10 ranks for each discipline using parallel SQL Query
language.

Table Creation:

SQL> Create Table university


(
collegecode int,
collegename varchar(255),
city varchar(255)
);
Table created.

SQL> Create table stu1


(
collegename varchar(255),
sturollno int,
stuname varchar(255),
department varchar(255),
CGPA int,
rank int
);
Table created.

SQL> insert into university values(11,'VVCOE','Tisaiyanvilai');


1 row created.
SQL> insert into university values(22,'SACOE','Tiruchendhur');
1 row created.
SQL> insert into university values(33,'NCE','Maruthakulam');
1 row created.
SQL> insert into university values(44,'NEC','Kovilpatti');
1 row created.
SQL> insert into university values(55,'SIT','Kariapatti');
1 row created.
SQL> insert into university values(66,'SUN','Nagercoil');
1 row created.
Parallel Query:

SQL> select * /*+ parallel */ FROM university;

COLLEGECODE 11
COLLEGENAME VVCOE
CITY Tisaiyanvilai

COLLEGECODE 22
COLLEGENAME SACOE
CITY Tiruchendhur

COLLEGE CODE 33
COLLEGENAME NCE
CITY Maruthakulam

COLLEGECODE 44
COLLEGENAME NEC
CITY Kovilpatti

COLLEGECODE 55
COLLEGENAME SIT
CITY Kariapatti

COLLEGECODE 66
COLLEGENAME SUN
CITY Nagercoil
6 rows selected.

SQL> insert into stu1 values('VVCOE',111,'mala','cse',8.8,3);


1 row created.
SQL> insert into stu1 values('SACOE',222,'sara','cse',8.4,6);
1 row created.
SQL> insert into stu1 values('NCE',333,'sindu','cse',8.5,5);
1 row created.
SQL> insert into stu1 values('NEC',444,'sheela','cse',8.6,4);
1 row created.
SQL> insert into stu1 values('SIT',555,'indu','cse',8.9,2);
1 row created.
SQL> insert into stu1 values('SUN',666,'seema','cse',9.0,1);
1 row created.

SQL> select * /*+ parallel */ FROM stu1;

COLLEGENAME VVCOE
STUROLLNO 111
STUNAME Mala
DEPARTMENT cse
CGPA 8.9
RANK 2
COLLEGENAME SACOE
STUROLLNO 222
STUNAME mani
DEPARTMENT cse
CGPA 8.0
RANK 6

COLLEGENAME SIT
STUROLLNO 333
STUNAME malini
DEPARTMENT cse
CGPA 8.6
RANK 3

COLLEGENAME NEC
STUROLLNO 444
STUNAME rose
DEPARTMENT cse
CGPA 9.2
RANK 1

COLLEGENAME SIT
STUROLLNO 555
STUNAME Nila
DEPARTMENT cse
CGPA 8.3
RANK 4

COLLEGENAME SUN
STUROLLNO 666
STUNAME jesi
DEPARTMENT cse
CGPA 8.2-
RANK 5

6 rows selected.

Query for parallel join:

SQL> SELECT /*+ parallel */ university.collegename, stu1. Sturollno ,stuname,cgpa,rank


FROM university FULL OUTER JOIN stu1 ON university.collegename=stu1.collegename
ORDER BY university.collegename;

COLLEGENAME NEC
STUROLLNO 444
STUNAME Rose
DEPARTMENT cse
CGPA 9.2
RANK 1
COLLEGENAME VVCOE
STUROLLNO 111
STUNAME mala
DEPARTMENT cse
CGPA 8.9
RANK 2

COLLEGENAME SIT
STUROLLNO 333
STUNAME malini
DEPARTMENT cse
CGPA 8.6
RANK 3

COLLEGENAME SIT
STUROLLNO 555
STUNAME Nila
DEPARTMENT cse
CGPA 8.3
RANK 4

COLLEGENAME SUN
STUROLLNO 666
STUNAME jesi
DEPARTMENT cse
CGPA 8.2
RANK 5

COLLEGENAME SACOE
STUROLLNO 222
STUNAME mani
DEPARTMENT cse
CGPA 8.0
RANK 6

RESULT:

Thus the parallel join and parallel sort algorithms to get the marks from different colleges of the
university and publish 10 ranks for each discipline using parallel SQL Query language was successfully
implemented.
EX.NO: 06 ACTIVE DATABASE-CREATION OF TRIGGERS AND
ASSERTIONS FOR BANK DATABASE

AIM:

To Create triggers and assertions for Bank database handling deposits and loan and
admission database handling seat allocation and vacancy position. Design the above relational
database schema and implement the following triggers and assertions.

a. When a deposit is made by a customer, create a trigger for updating customers account and bank
account
b. When a loan is issued to the customer, create a trigger for updating customer’s loan account and
bank account.
c. Create assertion for bank database so that the total loan amount does not exceed the total balance
in the bank.
d. When an admission is made, create a trigger for updating the seat allocation details and vacancy
position.

BANK DATABASE:-

Table Creation and Inserting values:-


Customer Table:-

SQL> create table customeracc(name varchar(30),accno number(10),balance number(10),


loanamount number(10));
Table created.

SQL> insert into customeracc values('Sindhu',711201,30000,2000);


1 row created.

Bank Table:-

SQL> create table bankacc(name varchar(30),accno number(10),balance number(10),loanamount


number(10));
Table created.

SQL> insert into bankacc values('Sindhu',711201,30000,2000);


1 row created.
SQL> insert into bankacc values('Jelcy',711202,40000,1000);
1 row created.
SQL> insert into bankacc values('Hema',711203,30000,100);
1 row created.
SQL> insert into bankacc values('Radha',711204,4000,300);
1 row created.
SQL> select * from bankacc;

NAME ACCNO BALANCE LOANAMOUNT


------------------------------ ---------- ---------- ----------
Sindhu 711201 30000 2000
Jelcy 711202 40000 1000
Hema 711203 30000 100
Radh 711204 4000 300

TRIGGER CREATION:-

SQL> create or replace trigger update_trigger


before update of balance
on customeracc
for each row
begin
update bankacc set balance=:new.balance where name=:new.name;
end;
/

Trigger created.

Normal Update:-

SQL> update customeracc set balance=40000 where accno=711201;

1 row updated.

SQL> select * from customeracc;

NAME ACCNO BALANCE LOANAMOUNT


-------------------------------------------------------------
Sindhu 711201 40000 2000

SQL> select * from bankacc;

NAME ACCNO BALANCE LOANAMOUNT


-------------------------------------------------------------
Sindhu 711201 40000 2000
Jelcy 711202 40000 1000
Hema 711203 30000 100
Radha 711204 4000 300

Updation in deposit with addition of pervious balance:-

SQL> update customeracc set balance=balance+&depositamt where accno=711201;


Enter value for depositamt: 5000
old 1: update customeracc set balance=balance+&depositamt where accno=711201
new 1: update customeracc set balance=balance+5000 where accno=711201

1 row updated.
SQL> select * from customeracc;

NAME ACCNO BALANCE LOANAMOUNT


-------------------------------------------------------------
Sindhu 711201 45000 2000

SQL> select * from bankacc;

NAME ACCNO BALANCE LOANAMOUNT


-------------------------------------------------------------
Sindhu 711201 45000 2000
Jelcy 711202 40000 1000
Hema 711203 30000 100
Radha 711204 4000 300

SQL> create table cusloan_acc(


name varchar(30),
accno number(10),
balance number(10),
loanamount number(10),
dueno number(10),
dueamount number(10));

Table created.

SQL> insert into cusloan_acc values('Sindhu',711201,30000,2000,2,250);


1 row created.

SQL> select * from cusloan_acc;

NAME ACCNO BALANCE LOANAMOUNT DUENO DUEAMOUNT


------------------------------------------------------------------------------------------
Sindhu 711201 30000 2000 2 250

SQL> create or replace trigger update_trigger


before update of loanamount
on cusloan_acc
for each row
begin
update bankacc set loanamount=:new.balance where name=:new.name;
end;
/

Trigger created.

SQL> update bankacc set loanamount=loanamount+&issueloanamt where accno=711201;


Enter value for issueloanamt: 2000
old 1: update bankacc set loanamount=loanamount+&issueloanamt where accno=711201
new 1: update bankacc set loanamount=loanamount+2000 where accno=711201

1 row updated.
SQL> select * from bankacc;

NAME ACCNO BALANCE LOANAMOUNT


------------------------------------------------------------
Sindhu 711201 45000 4000
Jelcy 711202 40000 1000
Hema 711203 30000 100
Radha 711204 000 300

SQL> select * from cusloan_acc;

NAME ACCNO BALANCE LOANAMOUNT DUENO DUEAMOUNT


----------------------------------------------------------------------------------------
Sindhu 711201 30000 4000 2 250

COLLEGE ADMISSION:-

Table Creation and inserting values:-


College Table:-

SQL> create table collegedb(collegename varchar(30),code number,ece number,cse number,it


number);
Table created.

SQL> insert into collegedb values('psna',9213,20,30,50);


1 row created.

University Table:-

SQL> create table universitydb(collegename varchar(30),code number,ece number,cse number,it


number);
Table created.
SQL> insert into universitydb values('psna',9213,20,30,50);
1 row created.
SQL> insert into universitydb values('ssn',2345,30,23,12);
1 row created.
SQL> insert into universitydb values('gct',3412,13,11,22);
1 row created.

SQL> select * from collegedb;

COLLEGENAME CODE ECE CSE IT


------------------------------ ---------- ---------- ---------- --------------------
psna 9213 20 30 50

SQL> select * from universitydb;

COLLEGENAME CODE ECE CSE IT


------------------------------ ---------- ---------- ---------- ---------------------
psna 9213 20 30 50
ssn 2345 30 23 12
gct 3412 13 11 22
Trigger Creation:-

SQL> create or replace trigger vaccany


after update of ece
on collegedb
for each row
begin
update universitydb set ece
=:new.ece where
code=:new.code;
end;
/
Trigger created.

Updation:-

SQL> update collegedb set ece=ece-&seatsno where code=9213;


Enter value for seatsno: 1
old 1: update collegedb set ece=ece-&seatsno where code=9213
new 1: update collegedb set ece=ece-1 where code=9213

1 row updated.

SQL> select * from collegedb;

COLLEGENAME CODE ECE CSE IT


------------------------------ ---------- ---------- ---------- ----------
psna 9213 19 30 50

SQL> select * from universitydb;

COLLEGENAME CODE ECE CSE IT


------------------------------ ---------- ---------- ---------- ----------
psna 9213 19 30 50
ssn 2345 30 23 12
gct 3412 13 11 22

RESULT:
Thus triggers and assertions for Bank database handling deposits and loan and
admission database handling seat allocation and vacancy position was created.
EX.NO: 07 IMPLEMENTATION OF DEDUCTIVE DATABASE-
KINSHIP DOMAIN APPLICATION

AIM:
To construct a knowlegde database for kinship domain(family relations) with facts.Extract
the following a relations using rules.Parent, Sibling, Brother,Sister, Child, Daughter, Son,
Spouse ,Wife, Husband, Grandparent, Grandchild, Cousin, Aunt and Uncle.
PROLOG:

Prolog stands for programming logic, Prolog is a high-level programming language based
on formal logic. Unlike traditional programing language that are based on performing sequences of
commands,Prolog is based on defining and then solving logical formulas.
Prolog is sometimes called a declarative language or a rule-based language because its
programs consists of a list of facts and rules. Prolog is used widely for artificial intelligence
applications, particularly expert systems.

PROCEDURE:

Start>>All programs>>SWI-Prolog>>Prolog
File>>New

Type the filename and select “save”

Type the coding in the window and Save it


Coding:
male(kasthuriSACOE).
male(dhanush).
male(selva).
male(yatra).
male(linga).
female(vijaya).
female(aishwarya).
female(geethanjali).
female(anjali).
parent(kasthuriSACOE,dhanush).
parent(vijaya,dhanush).
parent(kasthuriSACOE,selva).
parent(vijaya,selva).
parent(dhanush,linga).
parent(aishwarya,linga).
parent(dhanush,yatra).
parent(aishwarya,yatra).
parent(selva,anjali).
parent(geethanjali,anjali).

father(F,X):-male(F),parent(F,X).
mother(M,X):-female(M),parent(M,X).
sibling(X,Y):-father(Z,X),father(Z,Y).
child(C,P):-parent(P,C).
brother(B,X):-male(B),sibling(B,X).
sister(S,X):-female(S),sibling(S,X).
daughter(D,X):-female(D),parent(X,D).
son(S,X):-male(S),parent(X,S).
spouse(X,Y):-child(Z,X),child(Z,Y).
wife(W,X):-female(W),male(X),spouse(W,X).
husband(H,X):-male(H),female(X),spouse(H,X).
grandfather(GP,GC):-male(GP),parent(GP,X),parent(X,GC).
grandmother(GP,GC):-female(GP),parent(GP,X),parent(X,GC).
grandchild(GC,GP):-grandmother(GP,GC).
grandchild(GC,GP):-grandfather(GP,GC).
aunt(A,X):-female(A),father(Z,X),brother(Z,A).
aunt(A,X):-female(A),mother(Z,X),sister(Z,A).
uncle(U,X):-male(U),father(Z,X),brother(Z,U).
uncle(U,X):-male(U),mother(Z,X),sister(Z,U).
uncle(U,X):-male(U),father(Z,X),sister(S,Z),husband(U,S).
cousin(X,Y):-parent(Z,X),parent(P,Y),sibling(Z,P).
File>Save As
Enter the filename with extension .pl

Compile the code

Compile>>Compile
Execute with the commands

; at the end of statement indicates to display next valid data. . at the end of statements will end
the display of futher data even if available.

To Edit existing file “File>>Edit>>select the name of the file to be edited”.Make the modification
and use “File>>Save As” to save the file and Click “File>>Reload Modified Files” to load the
currently saved document and check the commands.

RESULT:
Thus the knowledge database for kinship domain with facts has been created and the rules
have been executed.
EX.NO: 08 CLASSIFICATION AND CLUSTERING OF TRAINING
DATA USING WEKA TOOL

AIM:

To implement classification and clustering algorithm for the given sample set using weka
tool

Working with weka tool for classifying and clustering algorithm:

Work with Weka tool classification and clustering algorithms using the given training data
and test with the unknown sample. Also experiment with different scenarios and large data set

wop210D.tmpMicrosoft_Office_Excel_97-2003_Worksheet1.xls

REQUIREMENTS:
1. one PC
2. Windows OS
3. WEKA tool 3.6
4. sample set in ARFF file or CSV file

PROCEDURE:
OPENING THE PROGRAM:
Once the program has been loaded on the user’s machine it is opened by navigating to
the programs start option and that will depend on the user’s operating system

Figure.1. opening weka tool


WEKA EXPLORER:
• Click the Explorer on Weka GUI Chooser
• On the Explorer window, click button “Open File” to open a data file from the folder where
your data files stored.
• Then select the desired module (Preprocess, Classify, Cluster, Association etc)

Figure 2 Choosing a file


Figure. 3 - classifier output

Figure .4 - shows the Cluster window and some of its options.


TREE VISUALIZATION:

Figure .5 - shows the tree visualization for our input

OUTPUT:

Classifier :

=== Run information ===


Scheme: weka.classifiers.bayes.NaiveBayes
Relation: sample
Instances: 15
Attributes: 6
RID
Age
Income
Student
Credit_rating
Class: buys_computer
Test mode: evaluate on training data

=== Classifier model (full training set) ===

Naive Bayes Classifier

Class
Attribute No Yes
(0.35) (0.65)
==============================
RID
mean 6.6 8.7
std. dev. 5.0833 3.6892
weight sum 5 10
precision 1 1

Age
youth 4.0 3.0
Middle_age 1.0 5.0
Senior 3.0 5.0
[total] 8.0 13.0

Income
High 4.0 3.0
Medium 1.0 7.0
Low 3.0 3.0
[total] 8.0 13.0

Student
No 3.0 6.0
Yes 4.0 6.0
[total] 7.0 12.0
Credit_rating
Fair 4.0 7.0
Excellent 3.0 5.0
[total] 7.0 12.0

Time taken to build model: 0 seconds

=== Evaluation on training set ===


=== Summary ===
Correctly Classified Instances 13 86.6667 %
Incorrectly Classified Instances 2 13.3333 %
Kappa statistic 0.7
Mean absolute error 0.2421
Root mean squared error 0.2947
Relative absolute error 53.6908 %
Root relative squared error 62.4573 %
Total Number of Instances 15

=== Detailed Accuracy By Class ===

TP Rate FP Rate Precision Recall F-Measure ROCArea Class


0.8 0.1 0.8 0.8 0.8 0.96 No
0.9 0.2 0.9 0.9 0.9 0.96 Yes
Weighted Avg. 0.867 0.167 0.867 0.867 0.867 0.96

=== Confusion Matrix ===

a b <-- classified as
4 1 | a = No
• 9 | b = Yes
Clustering output:
=== Run information ===
Scheme: weka.clusterers.DBScan -E 0.9 -M 6 -I
weka.clusterers.forOPTICSAndDBScan.Databases.SequentialDatabase -D
weka.clusterers.forOPTICSAndDBScan.DataObjects.EuclidianDataObject
Relation: sample
Instances: 15
Attributes: 6
RID
Age
Income
Student
Credit_rating
Class: buys_computer
Test mode: evaluate on training data

=== Model and evaluation on training set ===

DBScan clustering results


=======================================================================
=================
Clustered DataObjects: 15
Number of attributes: 6
Epsilon: 0.9; minPoints: 6
Index: weka.clusterers.forOPTICSAndDBScan.Databases.SequentialDatabase
Distance-type: weka.clusterers.forOPTICSAndDBScan.DataObjects.EuclidianDataObject
Number of generated clusters: 0
Elapsed time: .03

( 0.) 1,youth,High,No,Fair,No --> NOISE


( 1.) 2,youth,High,No,Excellent,No --> NOISE
( 2.) 3,Middle_age,High,No,Fair,Yes --> NOISE
( 3.) 4,Senior,Medium,No,Fair,Yes --> NOISE
( 4.) 5,Senior,Low,Yes,Fair,Yes --> NOISE
( 5.) 6,Senior,Low,Yes,Fair,No --> NOISE
( 6.) 7,Middle_age,Low,Yes,Excellent,Yes --> NOISE
( 7.) 8,youth,Medium,No,Excellent,Yes --> NOISE
( 8.) 9,youth,Low,Yes,Fair,No --> NOISE
( 9.) 10,Senior,Medium,Yes,Fair,Yes --> NOISE
(10.) 11,youth,Medium,Yes,Fair,Yes --> NOISE
(11.) 12,Middle_age,Medium,No,Excellent,Yes --> NOISE
(12.) 13,Middle_age,High,Yes,Excellent,Yes --> NOISE
(13.) 14,Senior,Medium,No,Fair,Yes --> NOISE
(14.) 15,Senior,High,Yes,Excellent,No --> NOISE

Clustered Instances

Unclustered instances : 15
RESULT:
Thus the implementation of classification and clustering algorithm for the given sample set
using weka tool is implemented successfully.
EX.NO: 09 IMPLEMENTATION OF QUERY OPTIMIZER

AIM:

To implement Query Optimizer with Relational Algebraic expression construction and


execution plan generation for choosing an efficient execution strategy for processing the given
query

DESCRIPTION:

Creation of Employee Database

SQL> CREATE TABLE employee


(
empid int NOT NULL,
empname varchar(50) NOT NULL,
designation varchar(30) NOT NULL,
location varchar(50) NOT NULL,
experience int NOT NULL,
CONSTRAINT emp_pk PRIMARY KEY (empid)
);

SQL> INSERT INTO employee VALUES(1001,'Murugan','Software Engineer','Bangalore',2);


1 row created.
SQL> INSERT INTO employee VALUES(1002,'Keerthika','Software Engineer','Kariapatti',1);
1 row created.
SQL> INSERT INTO employee VALUES(1003,'Swathika','Manager','London',10);
1 row created.
SQL> INSERT INTO employee VALUES(1004,'Ruba','Manager','London', 9);
1 row created.
SQL> INSERT INTO employee VALUES(1005,'Karthiga','Team Lead','Beijing',5);
1 row created.
SQL> INSERT INTO employee VALUES(1006,'Priya','Team Lead','Washington', 5);
1 row created.
SQL> INSERT INTO employee VALUES(1007,'Aruna','Manager','San Fransisco',9);
1 row created.
SQL> INSERT INTO employee VALUES(1008,'Sindu','Manager','Sydney', 8);
1 row created.
SQL> INSERT INTO employee VALUES(1009,'Vidya','Software Engineer','Cincinnati', 3);
1 row created.
SQL> INSERT INTO employee VALUES(1010,'Nandini','Database Administrator','Atlanta', 5);
1 row created.
SQL> INSERT INTO employee VALUES(1011,'Gayathri','Team Lead','Beijing',5);
1 row created.
SQL> INSERT INTO employee VALUES(1012,'Meena','Team Lead','Washington', 5);
1 row created.
SQL> INSERT INTO employee VALUES(1013,'Pricilla','Manager','San Fransisco',9);
1 row created.
SQL> INSERT INTO employee VALUES(1014,'Priyatharsini','Manager','Sydney', 8);
1 row created.
SQL> INSERT INTO employee VALUES(1015,'Ashok','Software Engineer','Cincinnati', 3);
1 row created.
SQL> INSERT INTO employee VALUES(1016,'Siva','Database Administrator','Atlanta', 5);
1 row created.
SQL> INSERT INTO employee VALUES(1017,'Karthiga','Team Lead','Beijing',5);
1 row created.
SQL> INSERT INTO employee VALUES(1018,'Preethi','Team Lead','Washington', 5);
1 row created.
SQL> INSERT INTO employee VALUES(1019,'Meenakshi','Manager','San Fransisco',9);
1 row created.
SQL> INSERT INTO employee VALUES(1020,'Selvi','Manager','Sydney', 8);
1 row created.
SQL> INSERT INTO employee VALUES(1021,'Praveena','Software Engineer','Cincinnati', 3);
1 row created.
SQL> INSERT INTO employee VALUES(1022,'Brindha','Database Administrator','Atlanta', 5);
1 row created.

SQL> Select * from employee;

EMPID EMPNAME DESIGNATION LOCATION EXPERIEN


CE
1001 Murugan Software Engineer Bangalore 2
1002 Keerthika Software Engineer Kariapatti 1
1003 Swathika Manager London 10

1004 Ruba Manager London 9

1005 Karthiga Team Leader Beijing 5

1006 Priya Team Leader Washington 5

1007 Aruna Manager San Francisco 9


1008 Sindu Manager Sydney 8
1009 Vidya Software Engineer cincinnati 3
1010 Nandini Database Administrator Atlanda 5
1011 Gayathri Team Leader Beijing 5
1012 Meena Team Leader Washington 5
1013 Pricilla Manager San Francisco 9
1014 Priyadharshini Manager Sydney 8
1015 Ashok Software Engineer cincinnati 3
1016 Siva Database Administrator Atlanda 5
1017 Karthiga Team Leader Beijing 5
1018 Preethi Team Leader Washington 5
1019 Meenakshi Manager San Francisco 9
1020 Selvi Manager Sydney 8

1021 Praveena Software Engineer cincinnati 3


1022 Brindha Database Administrator Atlanda 5

a) SQL>SELECT empid, empname FROM employee WHERE experience >5;

EMPID EMPNAME

1003 Swathika

1004 Ruba

1007 Aruna
1008 Sindu
1013 Pricilla
1014 Priyatharsini
1019 Meenakshi
1020 Selvi

b)Find all managers working at London Branch

SQL> SELECT empname FROM employee WHERE location='London' AND


designation='Manager';

EMPID EMPNAME DESIGNATION LOCATI EXPERIENCE EMPID


ON
1003 Swathika Manager London 10 1003
1004 Ruba Manager London 9 1004
SQL> SELECT PLAN_TABLE_OUTPUT FROM TABLE(DBMS_XPLAN.DISPLAY());

RESULT:
Thus the Query Processing for Implementation of an Efficient Query Optimizer is done and
executed successfully.
EX.NO: 10 DESIGNING XML SCHEMA FOR COMPANY
DATABASE

AIM

To Design XML Schema for the given company database and to implement the following
queries using XQuery.

SOFTWARE REQUIREMENTS:

• Oxygen Xml Editor

• BaseX 7.8.2

PROCEDURE

• Start the program.

• Create the xml schema in Oxygen Xml Editor for the corresponding database.

• Create a xml schema for Department using xml file with deptName, deptNo,
deptManagerSSN, deptManagerStartDate, deptLocation.

• Create a xml schema for Employee using xml file with empName, empSSN, empSex,
empSalary, empBirthDate, empDeptNo, empSupervisorSSN, empAddress, empWorksOn.

• Create a xml schema for Project using xml file with projName, projNo, projLocation,
projDeptNo, projWorker.

• Implement the following queries using XQuery in BaseX 7.8.2

• Retrieve the details of the queries from the database.

• Show the result.

• Stop the program.

To Design XML Schema for the given company database:

XML

//department.xml

<?xml version="1.0"?>
<departments>
<department>
<deptName>Research</deptName>
<deptNo>1</deptNo>
<deptMgrSSN>11</deptMgrSSN>
<deptMgrStartDate>1/1/2000</deptMgrStartDate>
<deptLocation>Kariapatti</deptLocation>
</department>
<department>
<deptName>Outsourcing</deptName>
<deptNo>2</deptNo>
<deptMgrSSN>22</deptMgrSSN>
<deptMgrStartDate>1/1/2001</deptMgrStartDate>
<deptLocation>Hyderabad</deptLocation>
</department>
</departments>

//employee.xml

<?xml version="1.0"?>
<employees>
<employee>
<empName>arthi</empName>
<empSSN>11</empSSN>
<empSex>Female</empSex>
<empSalary>900000</empSalary>
<empBirthDate>1-3-89</empBirthDate>
<empDeptNo>1</empDeptNo>
<empAddress>kknagarKariapatti</empAddress>
<empWorksOn>Web Mining</empWorksOn>
</employee>
<employee>
<empName>maliga</empName>
<empSSN>12</empSSN>
<empSex>Female</empSex>
<empSalary>300000</empSalary>
<empBirthDate>2-3-89</empBirthDate>
<empDeptNo>1</empDeptNo>
<empSupSSN>11</empSupSSN>
<empAddress>annanagarKariapatti</empAddress>
<empWorksOn>Cloud Computing</empWorksOn>
</employee>
<employee>
<empName>sindhu</empName>
<empSSN>13</empSSN>
<empSex>male</empSex>
<empSalary>300000</empSalary>
<empBirthDate>4-9-89</empBirthDate>
<empDeptNo>1</empDeptNo>
<empSupSSN>11</empSupSSN>
<empAddress>annanagarKariapatti</empAddress>
<empWorksOn>Cloud Computing</empWorksOn>
</employee>
<employee>
<empName>gg</empName>
<empSSN>14</empSSN>
<empSex>male</empSex>
<empSalary>300000</empSalary>
<empBirthDate>6-9-88</empBirthDate>
<empDeptNo>1</empDeptNo>
<empSupSSN>11</empSupSSN>
<empAddress>annanagarKariapatti</empAddress>
<empWorksOn>Web Mining</empWorksOn>
</employee>
<employee>
<empName>sruthi</empName>
<empSSN>22</empSSN>
<empSex>Female</empSex>
<empSalary>900000</empSalary>
<empBirthDate>3-3-89</empBirthDate>
<empDeptNo>2</empDeptNo>
<empAddress>T nagarKariapatti</empAddress>
<empWorksOn>BusinessProcess</empWorksOn>
</employee>
<employee>
<empName>dhanuhsya</empName>
<empSSN>23</empSSN>
<empSex>male</empSex>
<empSalary>300000</empSalary>
<empBirthDate>7-9-1992</empBirthDate>
<empDeptNo>2</empDeptNo>
<empSupSSN>22</empSupSSN>
<empAddress>T nagarKariapatti</empAddress>
<empWorksOn>BusinessProcess</empWorksOn>
</employee>
<employee>
<empName>dhanush</empName>
<empSSN>24</empSSN>
<empSex>Female</empSex>
<empSalary>400000</empSalary>
<empBirthDate>3-3-90</empBirthDate>
<empDeptNo>2</empDeptNo>
<empSupSSN>22</empSupSSN>
<empAddress>kknagarKariapatti</empAddress>
<empWorksOn>KnowledgeProcess</empWorksOn>
</employee>
<employee>
<empName>dhanu</empName>
<empSSN>25</empSSN>
<empSex>Female</empSex>
<empSalary>300000</empSalary>
<empBirthDate>3-5-90</empBirthDate>
<empDeptNo>2</empDeptNo>
<empSupSSN>22</empSupSSN>
<empAddress>annanagarKariapatti</empAddress>
<empWorksOn>KnowledgeProcess</empWorksOn>
</employee>
</employees>
//project.xml

<?xml version="1.0"?>
<projects>
<project>
<projName>Web Mining</projName>
<projNo>111</projNo>
<projLoc>Kariapatti</projLoc>
<projDeptNo>1</projDeptNo>
<projWorkers>
<projWorker>
<name>dhanu</name>
<name>jeyaraman</name>
</projWorker>
</projWorkers>
</project>
<project>
<projName>Cloud Computing</projName>
<projNo>112</projNo>
<projLoc>Kariapatti</projLoc>
<projDeptNo>1</projDeptNo>
<projWorkers>
<projWorker>
<name>arthi</name>
<name>jeyaraman</name>
</projWorker>
</projWorkers>
</project>
<project>
<projName>BusinessProcess</projName>
<projNo>221</projNo>
<projLoc>Kariapatti</projLoc>
<projDeptNo>2</projDeptNo>
<projWorkers>
<projWorker>
<name>dhanushya</name>
<name>J</name>
</projWorker>
</projWorkers>
</project>
<project>
<projName>KnowledgeProcess</projName>
<projNo>222</projNo>
<projLoc>Kariapatti</projLoc>
<projDeptNo>2</projDeptNo>
<projWorkers>
<projWorker>
<name>dhanu</name>
</projWorker>
</projWorkers>
</project>
</projects>
XML SCHEMA

//department.xsd

<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified"


xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="departments">
<xs:complexType>
<xs:sequence>
<xs:element name="department" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="deptName"/>
<xs:element type="xs:byte" name="deptNo"/>
<xs:element type="xs:byte" name="deptMgrSSN"/>
<xs:element type="xs:string" name="deptMgrStartDate"/>
<xs:element type="xs:string" name="deptLocation"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
//employee.xsd

<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified"


xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="employees">
<xs:complexType>
<xs:sequence>
<xs:element name="employee" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="empName"/>
<xs:element type="xs:byte" name="empSSN"/>
<xs:element type="xs:string" name="empSex"/>
<xs:element type="xs:int" name="empSalary"/>
<xs:element type="xs:string" name="empBirthDate"/>
<xs:element type="xs:byte" name="empDeptNo"/>
<xs:element type="xs:byte" name="empSupSSN" minOccurs="0"/>
<xs:element type="xs:string" name="empAddress"/>
<xs:element type="xs:string" name="empWorksOn"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

//project.xsd

<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified"


xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="projects">
<xs:complexType>
<xs:sequence>
<xs:element name="project" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="projName"/>
<xs:element type="xs:short" name="projNo"/>
<xs:element type="xs:string" name="projLoc"/>
<xs:element type="xs:byte" name="projDeptNo"/>
<xs:element name="projWorkers">
<xs:complexType>
<xs:sequence>
<xs:element name="projWorker">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="name" maxOccurs="unbounded"
minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

To implement the following queries using XQuery

XQUERY

1. Retrieve the department name, manager name, and manager salary for every department

let $d1:=doc("D:/department.xml")
let $d2:=doc("D:/employee.xml")
for $p1 in $d1/departments/department
for $p2 in $d2/employees/employee
where $p1/deptMgrSSN=$p2/empSupSSN
return<Result><dept>{$p1/deptName}</dept><mgrName>{$p2/empName}
</mgrName><mgrSal>{$p2/empSalary}</mgrSal></Result>

Output:

<?xml version="1.0" encoding="UTF-8"?>


<Result>
<dept>
<deptName>Research</deptName>
</dept>
<mgrName>
<empName>maliga</empName>
</mgrName>
<mgrSal>
<empSalary>300000</empSalary>
</mgrSal>
</Result>
<Result>
<dept>
<deptName>Research</deptName>
</dept>
<mgrName>
<empName>sindhu</empName>
</mgrName>
<mgrSal>
<empSalary>300000</empSalary>
</mgrSal>
</Result>
<Result>
<dept>
<deptName>Research</deptName>
</dept>
<mgrName>
<empName>gg</empName>
</mgrName>
<mgrSal>
<empSalary>300000</empSalary>
</mgrSal>
</Result>
<Result>
<dept>
<deptName>Outsourcing</deptName>
</dept>
<mgrName>
<empName>dhanuhsya</empName>
</mgrName>
<mgrSal>
<empSalary>300000</empSalary>
</mgrSal>
</Result>
<Result>
<dept>
<deptName>Outsourcing</deptName>
</dept>
<mgrName>
<empName>dhanush</empName>
</mgrName>
<mgrSal>
<empSalary>400000</empSalary>
</mgrSal>
</Result>
<Result>
<dept>
<deptName>Outsourcing</deptName>
</dept>
<mgrName>
<empName>dhanu</empName>
</mgrName>
<mgrSal>
<empSalary>300000</empSalary>
</mgrSal>
</Result>
2.Retrieve the employee name, supervisor name and employee salary for each employee who
works in the Research Department.

let $d1:=doc(“D:/employee.xml")
let $d2:=doc("D:/department.xml")
let $r:=$d2/departments/department[deptName="Research"]
let $sup:=$d1/employees/employee[empSSN=$r/deptMgrSSN]
for $p1 in $d1/employees/employee
where $p1/empDeptNo=$r/deptNo
return<Result><eName>{$p1/empName}</eName><supName>{$sup/empName}
</supName><empSal>{$p1/empSalary}</empSal></Result>

Output:
<?xml version="1.0" encoding="UTF-8"?>
<Result>
<eName>
<empName>arthi</empName>
</eName>
<supName>
<empName>arthi</empName>
</supName>
<empSal>
<empSalary>900000</empSalary>
</empSal>
</Result>
<Result>
<eName>
<empName>maliga</empName>
</eName>
<supName>
<empName>arthi</empName>
</supName>
<empSal>
<empSalary>300000</empSalary>
</empSal>
</Result>
<Result>
<eName>
<empName>sindhu</empName>
</eName>
<supName>
<empName>arthi</empName>
</supName>
<empSal>
<empSalary>300000</empSalary>
</empSal>
</Result>
<Result>
<eName>
<empName>gg</empName>
</eName>
<supName>
<empName>arthi</empName>
</supName>
<empSal>
<empSalary>300000</empSalary>
</empSal>
</Result>

3. Retrieve the project name, controlling department name, number of employees and total
hours
worked per week on the project for each project.

let $d1:=doc("D:/department.xml")
let $d2:=doc("D:/project.xml")
for $p1 in $d2/projects/project
let $dep:=$d1/departments/department[deptNo=$p1/projDeptNo]
return<Result><projName>{$p1/projName}</projName><depName>{$dep/deptName}
</depName><workers>{count($p1/projWorkers/projWorker/name)}</workers></Result>

Output:

<?xml version="1.0" encoding="UTF-8"?>


<Result>
<projName>
<projName>Web Mining</projName>
</projName>
<depName>
<deptName>Research</deptName>
</depName>
<workers>2</workers>
</Result>
<Result>
<projName>
<projName>Cloud Computing</projName>
</projName>
<depName>
<deptName>Research</deptName>
</depName>
<workers>2</workers>
</Result>
<Result>
<projName>
<projName>BusinessProcess</projName>
</projName>
<depName>
<deptName>Outsourcing</deptName>
</depName>
<workers>2</workers>
</Result>
<Result>
<projName>
<projName>KnowledgeProcess</projName>
</projName>
<depName>
<deptName>Outsourcing</deptName>
</depName>
<workers>1</workers>
</Result>

4. Retrieve the project name, controlling department name, number of employees and total
hours
worked per week on the project for each project with more than one employee working on
it.

let $d1:=doc("D:/department.xml")
let $d2:=doc("D:/project.xml")
for $p1 in $d2/projects/project
let $dep:=$d1/departments/department[deptNo=$p1/projDeptNo]
where count($p1/projWorkers/projWorker/name)>1
return<Result><projName>{$p1/projName}</projName><depName>{$dep/deptName}
</depName><workers>{count($p1/projWorkers/projWorker/name)}</workers></Result>

Output:

<?xml version="1.0" encoding="UTF-8"?>


<Result>
<projName>
<projName>Web Mining</projName>
</projName>
<depName>
<deptName>Research</deptName>
</depName>
<workers>2</workers>
</Result>
<Result>
<projName>
<projName>Cloud Computing</projName>
</projName>
<depName>
<deptName>Research</deptName>
</depName>
<workers>2</workers>
</Result>
<Result>
<projName>
<projName>BusinessProcess</projName>
</projName>
<depName>
<deptName>Outsourcing</deptName>
</depName>
<workers>2</workers>
</Result>

RESULT:
Thus the XML Schema for the given database has been executed and implemented
successfully.

You might also like