RuleGen by Example (1)

RuleGen is very easy to use, as demonstrated by following example.

Let's assume we have an EMPLOYEE table with columns EMPNO, ENAME, JOB, SALARY etc. And the following business rule needs to be implemented: "We do not allow two (or more) presidents".
First we need to tell RuleGen what (type of) transactions could possibly violate this rule. This is referred to as the "when" of the rule. In this case there are two types of transactions:

  1. Transactions that insert a president.
  2. Transactions that promote an employee to become a president.

Both types of transactions could introduce a second president which would not be allowed. In RuleGen we specify the when of this rule by writing two queries as follows:

 select 'rule needs to be validated'
from inserted_rows
where job='PRESIDENT'; 

 select 'rule needs to be validated'
from updated_rows
where old_job<>'PRESIDENT' and new_job='PRESIDENT'; 

The first query detects transactions that insert a president. The second query detects transactions that promote someone to become a president.

Next we need to tell RuleGen how to validate the rule. Again we do this by writing a query. The goal for this query is to detect whether the rule is violated, and if so to supply the error message that should be raised.

 select 'At most one president allowed. Found: '||to_char(num_pres)||'.'
from (select count(*) as num_pres
      from emp
      where job='PRESIDENT')
where num_pres > 1; 

Done. We have implemented this rule by just writing three queries. All you need to do now, is press a button to generate the trigger-code for this rule.

Download the quickstart guide in the Resources section to check out more examples, or take a look at another example now.


News & Events

Check out our new blog on triggers here.

Or follow us:

RuleGen 3.0 released

With the open architecture of release 3.0, RuleGen has set the path for the future. Improved code generation, transparent code deployment, and separation of design and runtime, are some of the key highlights of this new release.

Available now: AM4DP

Click to see book on Amazon

A great textbook about data integrity constraints in relational databases. This book describes the key concepts on which RuleGen is based. Click image to see reviews at Amazon, or here for quotes found on internet.