constraints
Posted in 1994
Topics: Stored Procedures & SPL, Triggers, Constraints & Referential Integrity
storm@geog.utah.edu asked about using constraints with Informix. I'm not sure
if we're using them the way he wants to, but we use check constraints and RI
constraints. We also use triggers and stored procedures to implement cross
database RI. I don't have any examples of the last use, but we do it with
triggers that run on delete--they check if rows exist using keys and raise
exceptions if so. If you need a complete example, let me know and I'll dig
something up.
The other constraints we use have syntax like:
check (ok_flg IN ('Y', 'N')) constraint constraintname
check (inv_typ in ('R', 'L', 'T' , 'U')) constraint constraintname
this would be done in the table definition ddl
the RI constraints come after the table definitions:
alter table add constraint
(foreign key (key column(s)) references tablename constraint constraintname
I don't know if the RI constraint comes later due to Informix, or due to the
way our data modeling tool generates ddls.
The constraints don's show up if you do a dbschema -t
you need to do the schema for the whole database. Also, if you're using
triggers and stored procedures for cross db RI, the stored procedures need to
be in all databases they affect. They also need to be in a program's default
database, even if it is not affected by the sp/trigger.