Trigger to check a foreign key without using foreign key

Trigger to check a foreign key without using foreign key

Post by Guy Colsou » Tue, 30 Apr 2002 05:50:15



Hello,

I want to use a trigger to check a foreign key.

Let's assume :

table LIGNES_V contains field ID_ARTICLE char(25)
table STOCK contains field S_ID char(10)

In table LIGNES_V, ID_ARTICLE must contain '' or a valid value from S_ID in
STOCK
(because of the '' -> could not use a standard foreign key)

In the update trigger of LIGNES_V, i placed

if update(id_article) and exists (select id_article from inserted where
(id_article>' ') and  (left(id_article,10) not in (select s_id from stock)))
 RAISERROR ( 'ID_ARTICLE does not match S_ID !',16,1 )

it works very fine and gives the correct result.

BUT : i assume that this request containing a sub-request will result in bad
performances.

Does somebody have an idea to write this trigger on a more-performing way ?

Thanks for help,

Kind regards,

Guy

 
 
 

1. Trigger to check a foreign key without using foreign key

Hello,

I want to use a trigger to check a foreign key.

Let's assume :

table LIGNES_V contains field ID_ARTICLE char(25)
table STOCK contains field S_ID char(10)

In table LIGNES_V, ID_ARTICLE must contain '' or a valid value from S_ID in
STOCK
(because of the '' -> could not use a standard foreign key)

In the update trigger of LIGNES_V, i placed

if update(id_article) and exists (select id_article from inserted where
(id_article>' ') and  (left(id_article,10) not in (select s_id from stock)))
 RAISERROR ( 'ID_ARTICLE does not match S_ID !',16,1 )

it works very fine and gives the correct result.

BUT : i assume that this request containing a sub-request will result in bad
performances.

Does somebody have an idea to write this trigger on a more-performing way ?

Thanks for help,

Kind regards,

Guy

2. RBS problem

3. foreign key w/o foreign/primary key

4. Indexes with Progress

5. Foreign Key as subset of Primary Key

6. MAGIC R.A.D.

7. Identification of a primary key/foreign key

8. What access method to use?

9. One FOREIGN KEY refrences a Table with two Primary Keys

10. Copying Primary Key to Foreign Key

11. Changing Primary Key Values when foreign key constraints exist

12. delete primary key records together with the foreign keys records

13. Help, foreign keys and index keys