RuleGen by Example (2)

[back]

Here's another example (given the well known EMP - DEPT database design:

"Departments that employ a manager, should also employ an administrator."

So when would this constraint need to be checked? Again we need to think about inserts, deletes or updates that could possibly violate this constraint:

  1. Whenever a MANAGER is inserted: we need to check if the department for this manager has an ADMNISTRATOR.
  2. Whenever an ADMINISTRATOR is deleted: we need to check if the department still complies with this business rule.
  3. Whenever we a) update job to MANAGER, or b) update job away from ADMINISTRATOR, or c) transfer a MANAGER or ADMINISTRATOR to another department.

In RuleGen we specify the above when for this rule in following three queries:

 select deptno
from inserted_rows
where job = 'MANAGER'

select deptno
from deleted_rows
where job = 'ADMIN'

select new_deptno as deptno
from updated_rows
where (old_job <> 'MANAGER' or updated_DEPTNO = 'TRUE' ) and new_job = 'MANAGER'
union
select old_deptno
from updated_rows
where old_job = 'ADMIN' and (new_job <> 'ADMIN' or updated_deptno = 'TRUE') 

And finally we need to specify the how for this rule.

Resources

News & Events

We'll be present at the OGH Apex day.

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.

Free demo

If you are located inside the Netherlands, you can request a free demo. Contact us at info@rulegen.com to setup an appointment.