Don't worry about the fact that it is inefficient, worry about the fact that it simply doesn't work
Person 2 inserts a row into table ''ApplicationFormCriteria'' but doesn't commit. The 'pseudo-RI' trigger fires and finds the parent row in 'ApplicationForm' so the row is deemed okay. Person 1 deletes the parent row from "ApplicationForm" - the 'pseudo-RI' trigger fires - and doesn't see the uncommitted row from the other session (that's the joy of Oracle - massive lack of interference on uncommitted data - your programmer may have a Sybase/MSSQL background) so the row deletes okay. Person 1 commits. Person 2 commits. Whoopsie. Regards Jonathan Lewis http://www.jlcomp.demon.co.uk The educated person is not the person who can answer the questions, but the person who can question the answers -- T. Schick Jr One-day tutorials: http://www.jlcomp.demon.co.uk/tutorial.html ____UK_______April 8th ____UK_______April 22nd ____Denmark__May 21-23rd ____USA_(FL)_May 2nd Three-day seminar: see http://www.jlcomp.demon.co.uk/seminar.html ____UK_(Manchester)_May ____Estonia___June (provisional) ____USA_(CA, TX)_August The Co-operative Oracle Users' FAQ http://www.jlcomp.demon.co.uk/faq/ind_faq.html ----- Original Message ----- To: "Multiple recipients of list ORACLE-L" <[EMAIL PROTECTED]> Sent: 01 April 2003 18:48 > Question: > > If some idiot decides to circumvent Oracle's referential integrity and > re-implement it by using triggers (insert, update, delete) that checks the > foreign (parent/child) key fields in other tables like this, > > declare numrows INTEGER; > begin > -- ApplicationForm is used if the state and other criteria match that > in > -- ApplicationFormCriteria ON PARENT DELETE RESTRICT > select count(*) into numrows > from ApplicationFormCriteria > where > ApplicationFormCriteria.applicationFormId = :old.applicationFormId; > if (numrows > 0) > then > raise_application_error( > -20343, > 'Database Integrity Violation - Cannot DELETE row in Table > ''ApplicationForm'' because referencing row exists in table > ''ApplicationFormCriteria'' for Primary Key (applicationFormId)=' || > :old.applicationFormId > ); > end if; > > > end; > > would it cause context switching between the SQL & PL/SQL engines? > > Yes, some genius did this in one of our databases. Two hundred > third/fourth normal form tables enforced by 800 triggers... I have him > registered to be stoned in public. > -- Please see the official ORACLE-L FAQ: http://www.orafaq.net -- Author: Jonathan Lewis INET: [EMAIL PROTECTED] Fat City Network Services -- 858-538-5051 http://www.fatcity.com San Diego, California -- Mailing list and web hosting services --------------------------------------------------------------------- To REMOVE yourself from this mailing list, send an E-Mail message to: [EMAIL PROTECTED] (note EXACT spelling of 'ListGuru') and in the message BODY, include a line containing: UNSUB ORACLE-L (or the name of mailing list you want to be removed from). You may also send the HELP command for other information (like subscribing).