HP 3000 Manuals

Creating Procedures and Rules [ ALLBASE/SQL Database Administration Guide ] MPE/iX 5.5 Documentation


ALLBASE/SQL Database Administration Guide

Creating Procedures and Rules 

Rules and procedures work together to provide a method of enforcing the
relationships in a database design without application programming.  You
create procedures, which are stored in the DBEnvironment; then you create
rules that invoke the procedures when certain conditions are met.  This
section shows how to create simple rules and procedures.  For more
detailed information, refer to the chapter "Constraints, Procedures and
Rules" in the ALLBASE/SQL Reference Manual.

Creating a Procedure 

You can create procedures that perform most database operations when
fired by a rule or when invoked in ISQL or in an application program.
The following example shows how to create procedure PurchDB.RemovePart,
which is invoked by the rule described in the following section:

     CREATE PROCEDURE PurchDB.RemovePart (PartNum CHAR(16) NOT NULL)
     AS BEGIN
        DELETE FROM PurchDB.Inventory WHERE PartNumber = :PartNum;
        DELETE FROM PurchDB.SupplyPrice WHERE PartNumber = :PartNum;
     END;

For more detailed information, refer to the "Using Procedures" section of
the "Constraints, Procedures, and Rules" chapter in the ALLBASE/SQL 
Reference Manual and to the "Using Procedures in Application Programs"
chapter in the ALLBASE/SQL Advanced Application Programming Guide.

Creating a Rule 

You can define rules that operate on specific tables in a database
whenever a particular type of data manipulation is performed.  The
following example shows how to create a rule tied to an update of the
PurchDB.Parts table:

     CREATE RULE PurchDB.RemovePart
        AFTER DELETE FROM PurchDB.Parts
        WHERE SUBSTRING(PartNumber,1,4) < > 'XXXX'
        EXECUTE PROCEDURE PurchDB.RemovePart (OLD.PartNumber);

The table on which the rule is defined is PurchDB.Parts.  The statement
type required to trigger the procedure is the DELETE operation.  The
condition that must be satisfied in addition to the statement type of
DELETE is that the first four characters in PartNumber must not be
"XXXX." The procedure to be executed is PurchDB.RemovePart.



MPE/iX 5.5 Documentation