Advanced Databases Laboratory-CP7211
Advanced Databases Laboratory-CP7211
Advanced Databases Laboratory-CP7211
IMPLEMENTATION DISTRIBUTED
1 DATABASE-BOOK STORE APPLICATION
IMPLEMENTATION OF DEADLOCK
2 DEDUCTION ALGORITHM FOR
DISTRIBUTED DATABASE
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
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:
8 rows selected.
SQL> insert into stock select ISBN,total_stock as qty, storeno from books1;
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.
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:
PROCEDURE:
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> ed dd3;
SQL> ed dd3;
SQL> @dd3;
41 /
TRANS LOCK WAIT
t1 x6 x2
t2 x4 x7
t4 x7
x7<-x7deadlock occured
no deadlock
SQL> ed dd4;
SQL> @dd4;
37 /
TRANS LOCK WAIT
t2 x5
t4 x8 x5
t5 x3 x7
x5<-x5deadlock occured
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)
--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
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:
Software Required:
• SQL Plus
• Oracle 9i
Table created.
Table created.
Table Create Statement For table_site3:
Table created.
Trigger Statement For Automatic Updation in site2 & site3:
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.
1 row updated.
SUM(VACANCY)
-----------------------
179
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.
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:
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.
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.
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:-
Bank Table:-
TRIGGER CREATION:-
Trigger created.
Normal Update:-
1 row updated.
1 row updated.
SQL> select * from customeracc;
Table created.
Trigger created.
1 row updated.
SQL> select * from bankacc;
COLLEGE ADMISSION:-
University Table:-
Updation:-
1 row updated.
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
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>>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
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
OUTPUT:
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
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
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:
DESCRIPTION:
EMPID EMPNAME
1003 Swathika
1004 Ruba
1007 Aruna
1008 Sindu
1013 Pricilla
1014 Priyatharsini
1019 Meenakshi
1020 Selvi
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:
• BaseX 7.8.2
PROCEDURE
• 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.
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
//project.xsd
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:
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:
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:
RESULT:
Thus the XML Schema for the given database has been executed and implemented
successfully.