which will fire first ? Trigger or Constraint

Answer Posted / lakkireddy ashok

Always trigger will fire first

eg:create table T_CHK (a number check (A < 99));

INSERT INTO T_CHK VALUES(101);

ORA-02290: check constraint (APPS.SYS_C00207769) violated

if u create trigger
CREATE TRIGGER CHKT BEFORE INSERT ON T_CHK
FOR EACH ROW
BEGIN
IF :NEW.A >100 THEN
RAISE_APPLICATION_ERROR(-20011,'VALUES SHOULD BE < 100');
END IF;
END;

INSERT INTO T_CHK VALUES(101);

ORA-20011: VALUES SHOULD BE < 100
ORA-06512: at "APPS.CHKT", line 3
ORA-04088: error during execution of trigger 'APPS.CHKT'

if u don't create trigger then constraint will be first otherwise if u create trigger to the same table with same DML operations here trigger will fire first instead of constraint firing

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

what is a database? : Sql dba

614


how can we submit a form without a submit button? : Sql dba

549


What is the difference between row level and statement level trigger?

530


What is clustered index sql?

510


What is percent sign in sql?

731






How to rename a table?

568


Is a secondary key the same as a foreign key?

500


What is the difference between inner join and left join?

552


What are string functions in sql?

688


Name the operator which is used in the query for pattern matching?

514


What is sql and how does it work?

557


define join and explain different type of joins? : Sql dba

559


Explain lock escalation? : Transact sql

713


How much does sqlite cost?

564


What are the constraints available in sql?

592