Trigger for upper bound on cardinality

General discussions about code engineering

Moderator: Moderators

Trigger for upper bound on cardinality

Postby vytautaslatvys@gmail.com » Thu May 07, 2015 10:54 am

Hi,

I am looking for a solution to implement trigger creation for tables those participate in association and have a specific upper bound on cardinality. For example, [0..4] or [1..3] ... [n..m], where n, m = 0, 1, 2, 3, ... Such restriction is represented by trigger in database. For instance, table1 [1]association[0..4] table2. Trigger for this association would be like this:

Code: Select all
CREATE OR REPLACE TRIGGER table2
BEFORE INSERT ON RATAI
FOR EACH ROW
DECLARE
  n_count NUMBER;
  upper_bound_violated EXCEPTION;
  PRAGMA EXCEPTION_INIT(upper_bound_violated, -20001);
BEGIN
  SELECT COUNT(*)
    INTO n_count
    FROM table2
    WHERE fk_table1 = :NEW.fk_table1;
   
  IF n_count = 4 THEN
    RAISE upper_bound_violated;
  END IF;
 
  EXCEPTION
    WHEN upper_bound_violated
      THEN raise_application_error(-20001, 'Number of objects those can reference to the same parent object was exceeded.');
END;


Is there any way i could achieve this? Thanks for helping.
vytautaslatvys@gmail.com
Forum Newbie
Forum Newbie
 
Posts: 3
Posts Rating:0
Joined: Wed May 06, 2015 8:36 am

Return to Code engineering

Who is online

Users browsing this forum: No registered users and 1 guest