Home > database >  In the insert trigger, the If statement execution after the Update (column name)?
In the insert trigger, the If statement execution after the Update (column name)?

Time:10-01

The create table T1
Int (A1, A2 char (4));

The create table T2
(B1 char (4), B2 int);

Alter the trigger tri1
On T1 after insert
As
If the update (A2)
The update T2 set B2=B2 + 1
Where b1=(select a2 from inserted)

Select * from T1
Select * from T2
Insert t2 values (' 1111 ', 20)
Insert t2 values (' 2222 ', 10)

Insert the t1 values (1, '1111')
Insert the t1 values (2, '2222')

The T1 table inserted, trigger, why? Always thought that triggers the if the update (column name) is only for the update action works,

CodePudding user response:

 
- you this itself is inserted into the trigger, you joined (insert) field, if is it inserts need to be updated is modified to Update

If the Update (field)

The Begin
- write a modify this field here you need to do operation

End

CodePudding user response:

If the update is to tell you which column is modified
  • Related