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