Oracle 7 does not support creation of domains or general assertions, but has 'found' database triggers.
The Oracle SQL syntax allows for definition of primary keys, candidate keys, foreign keys and for record constraints (using the check clause)
on delete cascade is also supported for foreign keys ( but not on update )
The current version of Oracle does not support the create domain or create assertion commands.
primary key supported by `DUPLICATES NOT ALLOWED' in key declaration
foreign key supported by the DBTG set structure
a domain constraint on city in the supplier table
create assertion s1 check
( not exists
( select * from supplier
where city not in (`Sydney', `Melbourne', `Canberra')
)
)
/* can't create assertions in current version of Oracle */
create table supplier
( S# etc,
. . . ,
constraint s1 check (city in ('Sydney', 'Melbourne', 'Canberra'))
)
/* this can be done in Oracle and, in fact, may be better as a table constraint
than as a general constraint, but it is not quite the same as defining, and
then using, a new domain. */
create table supplier
( S# etc,
city varchar(16) constraint s1
check (city in ('Sydney', 'Melbourne', 'Canberra'))
)
assert e1 on update of emp(salary):
new salary > old salary
(can't do this in SQL/92 or in Oracle)
`Cascade delete' on deletion of Supplier record
define trigger SDel on deletion of Supplier:
delete Shipment
where Shipment.S# = old Supplier.S#
/* no triggers in SQL/92, but cascade delete
supported in foreign key constraint */
. . .
constraint SDel foreign key(S#)
references Supplier(S#) on delete cascade
/* this is supported in Oracle too */
create assertion Ship1 check
( not exists
( select * from shipment
where S# not in
( select S# from supplier)))
/* Better to use a foreign key table constraint */
create assertion Sydney_quantity check
( not exists
( select * from shipment
where quantity < 100
and S# in
( select S# from supplier where city = 'Sydney')))
Can't do this as a table constraint in Oracle, but you could develop a
(complex) database trigger to prevent illegal data from being entered
Here is a simple Oracle database trigger to accomplish `cascade update' (not yet supported as a table constraint in Oracle). Oracle database triggers are defined using PL/SQL.
create trigger S#_cascade
after update of S# on Supplier
for each row
begin
update shipment set S# = :new.S#
where S# = :old.S#;
end;
in Shipment create table statement
. . . quantity NUMBER check (quantity > 0),( in some table with a column `State')
. . .
State CHAR(20) check (State in (`Tasmania', `Victoria', `New South Wales',
South Australia', `Queensland'))
( in say the emp table )
. . .
Surname CHAR(20) constraint CapSurName
check (Surname = UPPER(Surname)),
. . . check (EndDate > StartDate)/*Note this can not be a column constraint*/
Back to INFS3055 page.
Vicki Peterson
Last modified: Mon May 11 22:06:34 EST 1998
Queries to : help3055@iwaki.anu.edu.au