8. SQL Statements : CREATE RULE : Syntax
 
Share this page                  
Syntax
The CREATE RULE statement has the following format:
[EXEC SQL] CREATE RULE [schema.]rule_name table_condition
              [FOR EACH {ROW | STATEMENT}]
              EXECUTE PROCEDURE [schema.]proc_name[(parameter = value
                            {, parameter = value})]
The table_condition has the following format:
BEFORE|AFTER statement_type {, statement_type} ON|OF|FROM|INTO [schema.]table_name
     [REFERENCING [OLD AS old_corr_name] [NEW AS new_corr_name]]
     [WHERE qualification]
Note:  The keyword TRIGGER can be used as an alias for RULE.
rule_name
Specifies the name of the rule.
Rules can be defined against base tables and against views if the view is updatable. For restrictions, see Create View (see CREATE VIEW).
Limits: The rule name must be a valid object name (see Object Naming Rules) that is unique within the set of rules owned by the user issuing the CREATE RULE statement.
table_condition
Defines the action that fires the rule. For details, see Table_Condition (see Table_Condition).
FOR EACH ROW|STATEMENT
Defines a row- or statement-level rule. For details, see Row and Statement Level Rules (see Row and Statement Level Rules).
proc_name
Specifies the procedure to be executed when a statement fires the rule. The procedure must exist at the time the rule is created. For details, see Procedure Execution in Create Rule (see Procedure Execution in Create Rule).
parameter
Specifies one or more values to be passed to the procedure. Not all of the parameters appearing in the definition of the invoked procedure have to be included. However, those that are included must match in name and data type. Parameters can be specified using host language variables. Parameters cannot be passed by reference to a procedure that is executed by a rule.
value
Contains a constant or an old or new value in the row that caused the rule to fire. Constant values cannot contain function expressions. If value represents a row value, it must be qualified by a correlation name. For details, see the description of the referencing clause.