Skip to content
Advertisement

SQL Trigger with loop from another table

I’ve got 2 tables :

Table A

Table B

The table A contains the following values :

The Table B contains the following values :

My goal is to set the column B.chk with the number of occurence from table A when a new row is created on table B.

For example :

The trigger on table B should set B.Chk at 1 cause the following query is matching with the table A

For this i should create a trigger on Table B but don’t know how to “loop” on the other table. Should i user for, while or a cursor ?

Advertisement

Answer

You was right, i don’t need a loop but chk column need to be set immediately after insert.

Here is my trigger :

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement