Beruflich Dokumente
Kultur Dokumente
EXPT.
EXPERIMENT
PAGE
NO.
NO.
NAME
1
Distributed Database for Bookstore
3
(EER)
4
Parallel Database University Counselling for Engineering
7
Deductive Database Constructing Knowledge Database for
8
Study and Working of WEKA Tool
9
Query Processing Implementation of an Efficient Query
Optimizer
10
Designing XML Schema for Company Database
DATE:
EX.NO:
DISTRIBUTED DATABASE
AIM:
To develop and write SQL queries for a distributed database of BookStore at four sites S1, S2, S3
and S4. The Bookstores are divided into four sites by their ZIP codes.
Distributed Database Design Description:
A distributed database is a database in which storage devices are not all attached to a common
processing unit such as the CPU, controlled by a distributed database management system.
(together sometimes called a distributed database system). It may be stored in multiple
computers, located in the same physical location; or may be dispersed over a network of
interconnected computers. Unlike parallel systems, in which the processors are tightly coupled and
constitute a single database system, a distributed database system consists of loosely-coupled sites
that share no physical components.
There are two principal approaches to store a relation r in a distributed database system:
Replication
Fragmentation/Partitioning
Replication: In replication, the system maintains several identical replicas of the same relation r
in different sites.
Data is more available in this scheme.
Parallelism is increased when read request is served.
Increases overhead on update operations as each site containing the replica needed to be
updated in order to maintain consistency.
Multi-datacenter replication provides geographical diversity:
Fragmentation: The relation r is fragmented into several relations r1, r2, r3....rn in such a way that the
actual relation could be reconstructed from the fragments and then the fragments are scattered to
different locations. There are basically two schemes of fragmentation:
Horizontal fragmentation - splits the relation by assigning each tuple of r to one or more
fragments.
Vertical fragmentation - splits the relation by decomposing the schema R of relation r.
Implementing distributed databases using SQL Server 2005
Linked servers provide SQL Server the ability to access data from remote data sources. Using
these mechanisms, we can issue queries, perform data modifications and execute remote
procedures. We can use the T-SQL function OPENROWSET to query a remote data source
without a linked server.
Steps:
1. Create Horizontal Partition:
First partition a table horizontally. In designing a partitioning scheme, it must be clear
what data belongs to each member table. The original table is replaced with several
smaller member tables. Each member table has the same number of columns as the
original table, and each column has the same attributes as the corresponding column in
the original table, such as data type, size, and collation. By using a distributed
partitioned view, each member table is on a separate member server. For the greatest
location transparency, the name of the member databases should be the same on each
member server, although this is not required.For
example: Server1.CustomerDB, Server2.CustomerDB, Server3.CustomerDB. 1.1
Creating Member Tables
Design the member tables so that each table stores a horizontal slice of the original table based
on a range of key values. The ranges are based on the data values in a partitioning column. The
range of values in each member table is enforced by a CHECK constraint on the partitioning
column, and ranges cannot overlap.The CHECK constraint for this table is the following:
-- On Server1:
CREATE TABLE Customers_33 (CustomerID INTEGER PRIMARY KEY
CHECK (CustomerID BETWEEN 1 AND 32999),
[ , [ @location= ] 'location' ]
Parameter
Description
server
Local name used for the linked server.
product_name
Product name of the OLE DB data source. For SQL Server instances, the
This is the unique programmatic identifier for the OLE DB provider. When not
provider_name
specified, the provider name is the SQL Server data source. The explicit
provider_name for SQL Server is SQLNCLI (for Microsoft SQL Native Client
OLE DB Provider).
data_source
This is the data source as interpreted by the OLE DB provider.
location
The location interpreted by the OLE DB provider.
provider_string
The connection string specific to the OLE DB provider.
catalog
This varies from the database systems.
Add linked server definitions on each member server that contains the connection
information required to run distributed queries on the other member servers. This gives
a distributed partitioned view access to data on the other servers.
Defining Distributed Partition Views:
After you create the member tables, you define a distributed partitioned view on each
member server, with each view having the same name. This enables queries that
reference the distributed partitioned view name to run on one or more of the member
servers. The system operates as if a copy of the original table is on each member
server, but each server has only a member table and a distributed partitioned view.
Create the following distributed partitioned view:
CREATE VIEW Customers AS select statement
To execute queries on the remote instance, Distributed queries referring to linked server
name is written by using the following syntax
[linked_server_name].[catalog].[schema].[object_name]
Create a distributed partitioned view on other server instances also.
Queries:
1. Insert and Display details in each table.
select sum(totalstock) 'Total Books' from BooksView where price between 25 and 100 3.
Update the book price of book No=1234 from $45 to $55 at site S3.
(1 row(s) affected)
4. Find total number of book at site S2.
select *from openquery(cs03c025,'select sum(totalstock) from bookstore.dbo.Books')
Create three databases names S1,S2,S3,S4. Create the following tables in all of them
USE [S1]
GO
/****** Object: Table [dbo].[Books] Script Date: 3/8/2014 4:10:30 AM ******/
SET ANSI_NULLS ON GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Books](
[ISBN] [uniqueidentifier] NOT NULL, [PrimaryAuthor] [varchar](50) NULL, [Topic] [varchar]
(50) NULL, [TotalStock] [int] NULL,
[Price] [decimal](18, 0) NULL,
GO
SET ANSI_PADDING OFF
GO
USE [S4]
GO
/****** Object: Table [dbo].[BookStore] Script Date: 3/8/2014 3:07:23 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[BookStore]( [StoreNo] [uniqueidentifier] NOT NULL, [City] [varchar]
(50) NULL,
[State] [varchar](50) NULL, [Zip] [varchar](50) NULL,
USE [S4] GO
drop table [Stock]
/****** Object: Table [dbo].[Stock] Script Date: 3/8/2014 3:07:50 AM ******/
SET ANSI_NULLS ON GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Stock](
[StoreNo] [uniqueidentifier] NOT NULL, [ISBN] [uniqueidentifier] NOT NULL,
GO
SET ANSI_PADDING OFF
GO
ALTER TABLE [dbo].[Stock] WITH CHECK ADD CONSTRAINT [FK_Stock_BookStore]
FOREIGN KEY([StoreNo])
REFERENCES [dbo].[BookStore] ([StoreNo]) GO
ALTER TABLE [dbo].[Stock] CHECK CONSTRAINT [FK_Stock_BookStore] GO
select * from s1.dbo.Books select * from s2.dbo.Books select * from s3.dbo.Books select * from
s4.dbo.Books
insert into s1.dbo.BookStore values(newid(),'Chicago','IL','60661',10000); insert into
s2.dbo.BookStore values(newid(),'Boston','MA','2233',30000); insert into s3.dbo.BookStore
values(newid(),'Albany','NY','1134',60000); insert into s4.dbo.BookStore
values(newid(),'LasVegas','CA','5677',80000);
--Find the total number of books in stock where price is between $15 and $55
Create view BooksView as
(
select * from s1.dbo.Books union select * from s2.dbo.Books union select * from s3.dbo.Books
union select * from s4.dbo.Books
)
select * from BooksView
Create view BookStoreView as
(
select * from s1.dbo.BookStore union select * from s2.dbo.BookStore union select * from
s3.dbo.BookStore union select * from s4.dbo.BookStore
)
select * from BookStoreView
)
--Find the total number of books in stock where price is between $15 and $55
group by bv.ISBN
--Update the bookprice of bookNo=1234 from $45 to $55 at site S3.
update s3.dbo.books set price=55 where topic='Einthir manithan'
--Find total number of book at site S2.
select sum(sv.Qty) from s2.dbo.books bv
inner join s2.dbo.Stock sv on sv.ISBN=bv.ISBN
inner join s2.dbo.books bvs on bvs.StoreNo=sv.StoreNo group by bv.ISBN
Result:
Thus the Distributed Database has been developed and executed successfully.
DATE:
EX.NO:
CODINGS:
Connected to:
Oracle9i Release 9.0.1.1.1 - Production
JServer Release 9.0.1.1.1 - Production
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.
LOC WAIT
SITE
t4
x8
x5
s3
t5
x3
x7
s3
8 rows selected.
SQL> ed dd1;
SQL> set serveroutput on; SQL> @dd1;
42 /
SELECT trans, lock1, wait
*
ERROR at line 3: ORA-06550: line 3, column
15:
PL/SQL: ORA-00904: invalid column name
ORA-06550: line 3, column 1:
PL/SQL: SQL Statement ignored ORA-06550: line
5, column 34:
t3
x2
x7
t4
x7
t4
x8
x5
t5
x3
x7
x5<-x5deadlock occured x2<-x2deadlock occured
t2
x4
x7
t4
x7
x7<-x7deadlock occured no deadlock
PL/SQL procedure successfully completed.
SQL> ed dd4; SQL> @dd4; 37 /
SELECT trans, loc, wait
*
ERROR at line 3: ORA-06550: line 3, column 15:
PL/SQL: ORA-00904: invalid column name ORA-06550: line 3,
column 1:
PL/SQL: SQL Statement ignored ORA-06550: line 2, column 9:
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
SQL>
DD1 :
declare cursor c1 is
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;
DD2:
declare cursor c1 is
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;
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();
dbms_output.put_line(ll(i)||'<-'||l2(j)||'deadlock
occured'); end if;
end loop; end loop;
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;
Result:
Thus the Deadlock Detection Algorithm Distributed Database has been developed and
executed successfully.
DATE:
EX.NO:
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
go
insert into dbo.SubRoles values(1,'Technicians') go
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
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
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
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
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 Fulltime SubRole - filtered)
iv Modify User details v Delete User details --iv 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
where SubRoleID in (4,5) --This condition avoids the control to check in all
the rows
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:
EX.NO:
AIM:
To implement University Counselling for Engineering Colleges using Parallel Database.
Description:
A variety of hardware architectures allow multiple computers to share access to data, software, or
peripheral devices. A Parallel Database is designed to take advantage of such architectures by running
multiple instances which "share" a single physical database. In appropriate applications, a parallel
server can allow access to a single database by users on multiple machines, with increased
performance.
SQL Query:
The College details, Department details and Vacancy Details are maintained in 3 different sites. By
using the information from these 3 sites, seats can be allocated to a student using Parallel Query
Processing.
1.CREATE TABLE hr.admin_emp_dept
PARALLEL COMPRESS
AS SELECT * FROM hr.employees
WHERE department_id = 10;
In this case, the PARALLEL clause tells the database to select an optimum number of parallel execution
servers when creating the table.
parallel query with intra- and inter-operation parallelism, consider a more complex query:
2.SELECT /*+ PARALLEL(employees 4) PARALLEL(departments 4)
USE_HASH(employees) ORDERED */
GROUP BY employees.department_id;
RESULT:
Thus the Object Parallel Database fo r University Counselling for Engineering colleges
has been developed and executed successfully.
DATE:
EX.NO:
width to act as a join key, but character columns must be of the same width in order to be a join
key.
Parallel Sort-Merge Method:
SQL Query:
The first parallel join example is a basic SQL query that creates a pair-wise join of two Server
tables, table1 and table2.
1.CREATE TABLE junk as
SELECT *
from path1.table1 a,
path1.table2 b
where a.i = b.i;
2.creates a table which is the result of union of two parallel joins and this example
shows how the sort merges are used for the joins.
CREATE TABLE junk as
SELECT *
from path1.table1
where a.i = b.i
UNION
a, path1.table2 b
SELECT *
from path1.dansjunk3
c, path1.dansjunk4 d
where c.i = d.i;
3. The Parallel Join Facility also includes enhancements for data summarization by
using GROUP BY technique. The following example shows the combined use of both
the parallel join and parallel GROUP BY methods.
CREATE TABLE junk as
SELECT a.c, b.d, sum(b.e) from path1.table1a, path1.table2b
Where
a.i =b.i
GROUP BY a.d, b.d;
RESULT:
Thus the Object Parallel Database fo r University Counselling for Engineering colleges
has been developed and executed successfully.
DATE:
EX.NO:
Aim:
To create Triggers and Assertions for Bank Database handling deposits and loan and for Admission
Database handling seat allocation and vacancy position.
Description:
An active database is a database that includes an event-driven architecture which can
respond to conditions both inside and outside the database. Possible uses include security
monitoring, alerting, statistics gathering and authorization.
Most modern relational databases include active database features in the form of database
triggers.
Typically this behavior is described by event-condition-action (ECA) rules.
ECA rules comprise three components: event E, condition C, and action A.
The event describes an external happening to which the rule may be able to respond. The condition
examines the context in which the event has taken place.
The action describes the task to be carried out by the rule if the relevant event has taken place
and the condition has evaluated to true. In sum, if the specified event E occurs and if the
condition C is true then the specified action A is executed.
Triggers:
A trigger is a PL/SQL block or a PL/SQL procedure that executes implicitly whenever a
particular event takes place. It can either be:
Application trigger: Fires whenever an event occurs with a particular application.
Database Trigger: Fires whenever a data event (such as DML) occurs on a schema or database.
Elements in a Trigger:
Trigger timing
o For table: BEFORE, AFTER o For view: INSTEAD OF
After triggers are used when the triggering statement is to be completed before the
triggering action and to perform a different action on the same triggering statement if a
BEFORE trigger is already present.
Instead of Triggers are used to provide a transparent way of modifying views that
cannot be modified directly through SQL DML statements because the view is not
inherently modifiable. You can write INSERT, UPDATE, and DELETE statements
against the view. The INSTEAD OF trigger works invisibly in the background performing
the action coded in the trigger body directly on the underlying tables.
Triggering user events:
INSERT UPDATE DELETE
Trigger Components:
Statement: The trigger body executes once for the triggering event. This is the default. A
statement trigger fires once, even if no rows are affected at all.
Row: The trigger body executes once for each row affected by the triggering event. A row
trigger is not executed if the triggering event affects no rows.
Trigger Body:
The trigger body is a PL/SQL block or a call to a procedure.
Syntax:
CREATE [OR REPLACE] TRIGGER trigger_name Timing
Event1 [OR event2 OR event3] ON table_name
Trigger_body
Assertions
An assertion is a predicate expressing a condition we wish the database to always
satisfy. Domain constraints, functional dependency and referential integrity are special
forms of assertion.
Where a constraint cannot be expressed in these forms, we use an assertion, e.g.
Ensuring the sum of loan amounts for each branch is less than the sum of all account
balances at the branch.
Ensuring every loan customer keeps a minimum of $1000 in an account. An assertion in
When a deposit is made by a customer, create a trigger for updating customers account
and bank account
Create or replace trigger t1 after insert on dep09 for each row
begin
if :new.damt>0 then
update cust09 set cbal=cbal+:new.damt where :new.ano=cust09.ano; update bank09
set asset=asset+:new.damt where :new.brid=bank09.brid; end if;
end;
When a loan is issued to the customer, create a trigger for updating customers loan
account and bank account.
Create or replace trigger t2 after insert on loan09 for each row
begin
if :new.lamt>0 then
update cust09 set cbal=cbal+:new.lamt where :new.ano=cust09.ano; update bank09 set
asset=asset-:new.lamt where :new.brid=bank09.brid; dbms_output.put_line('customer and bank
account updated');
end if; end;
c.
Create assertion for bank database so that the total loan amount does not
exceed the total balance in the bank.
create or replace assertion check (select sum(amt) from jloan where
jloan.name=jbranch.name)>=(select sum(amt) from jaccount where
jaccount.name=jbranch.name)
d. When an admission is made, create a trigger for updating the seat allocation details
and vacancy position.
Create or replace trigger t3 after insert on ad09 for each row
declare
a number(5):=0; begin
) ON [PRIMARY] GO
SET ANSI_PADDING OFF GO
Data to be inserted
CNO FirstName
LastName
ZipCode
CREATE TABLE [dbo].[CustomerAccount]( [AccountNo] [int] NOT NULL, [Location] [varchar](50) NULL,
[CNO] [int] NOT NULL,
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
AccountNo Location
CNO
Amount
ApprovedLoanAmount
1000
Chennai
1
1000
500
CustomerBankAccount
USE [Bank]
GO
/****** Object:
Table [dbo].[CustomerBankAccount]
Script Date: 01/01/2014 18:29:36
******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
) ON [PRIMARY]
GO
GO
3
NULL NULL
CustomerLoanAccount
USE [Bank]
GO
/****** Object: Table [dbo].[CustomerLoanAccount]
******/
SET ANSI_NULLS ON GO
SET QUOTED_IDENTIFIER ON GO
SET ANSI_PADDING ON GO
CREATE TABLE [dbo].[CustomerLoanAccount]( [CLNO] [int] NOT NULL,
Bandmaster
USE [Bank]
GO
/****** Object: Table [dbo].[BankMaster] Script Date: 01/01/2014 18:29:57 ******/
SET ANSI_NULLS ON GO
SET QUOTED_IDENTIFIER ON GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[BankMaster]( [BankID] [int] NOT NULL, [Name] [varchar](50) NOT NULL,
[Allocated] [int] NOT NULL, [Vacancy] [int] NOT NULL
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
BankID
Name
Allocated
Vacancy
1
LLFC
4
196
The scenarios are explained using the following triggers
When a deposit is made by a customer, create a trigger for updating customers account
and bank account
USE [Bank] GO
/****** Object: Trigger [dbo].[CustomerAccountTrigger] Script Date: 01/01/2014 18:21:42
******/
SET ANSI_NULLS ON GO
SET QUOTED_IDENTIFIER ON GO
ALTER TRIGGER [dbo].[CustomerAccountTrigger] ON [dbo].[CustomerAccount]
AFTER INSERT,UPDATE AS
BEGIN
SET NOCOUNT ON added to prevent extra result sets from
interfering with SELECT statements.
END
Create assertion for bank database so that the total loan amount does not exceed
the total balance in the bank.
When a loan is issued to the customer, create a trigger for updating customers loan
account and bank account.
USE [Bank] GO
/****** Object: Trigger [dbo].[CustomerLoanTrigger]
******/
SET ANSI_NULLS ON GO
SET QUOTED_IDENTIFIER ON GO
AFTER INSERT,UPDATE AS
BEGIN
SET NOCOUNT ON added to prevent extra result sets from
interfering with SELECT statements.
Declare @loanamount as int
Declare @cno as int
Declare @balance as decimal(18,0)
select @loanamount=ApprovedLoanAmount,@cno=CNO,@balance=Amount from
inserted
select @balance=Amount from CustomerBankAccount where CNO=@cno
if(@loanamount>@balance) Begin
END
When an admission is made, create a trigger for updating the seat allocation details and
vacancy position.
USE [Bank] GO
/****** Object: Trigger [dbo].[BankMasterTrigger]
******/
SET ANSI_NULLS ON GO
SET QUOTED_IDENTIFIER ON GO
AFTER INSERT,UPDATE AS
BEGIN
SET NOCOUNT ON added to prevent extra result sets from
interfering with SELECT statements.
Declare @count as int
select @count=COUNT(1) from inserted
SET NOCOUNT ON; if(@count>0)
Begin
update BankMaster set Allocated=Allocated+1,Vacancy=Vacancy-1 End
END
RESULT:
Thus the Active Database fo r Implementation of Triggers & Assertions for Bank
database has been developed and executed successfully.
DATE:
EX.NO:
DEDUCTIVE DATABASE
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
parent(kasthuriraja,dhanush). parent(vijaya,dhanush).
parent(kasthuriraja,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
; 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.
DATE:
EX.NO:
RID
Age
Income
Student
Credit_rating
Class:buys_computer
1
youth
high
no
fair
no
2
youth
high
no
excellent
no
3
middle_aged
high
no
fair
yes
4
senior
medium
no
fair
yes
5
senior
low
yes
fair
yes
6
senior
low
yes
excellent
no
7
middle_aged
low
yes
excellent
yes
8
youth
medium
no
fair
no
9
youth
low
yes
fair
yes
10
senior
medium
yes
fair
yes
11
youth
medium
yes
excellent
yes
12
middle_aged
medium
no
excellent
yes
13
middle_aged
high
yes
fair
yes
14
senior
medium
no
excellent
no
Snapshots: