SQL creation triggers
Create TRIGGER syntax
Create Trigger Triggername on TableName
For Insert |delete|update
As
Begin
End
Come on, look at that. Create an instance of a trigger
CREATE TABLE Ta1
(
Taid int Identity (1001,1) primary key,
Taname varchar is not NULL,
TASL int
)
CREATE TABLE Ta2
(
ta2id int Identity (1001,1) primary key,
Ta2name varchar is not NULL,
Ta2ysh int,
TA2SL int
)
Create Trigger Tru_ta1
On TA1
For update
As
Begin
if exists (select 1 from ta2,inserted where Ta2id=taid and Ta2ysh < TASL)
Rollback
Else
Update TA2 Set TA2SL=TASL
From inserted where Ta2id=taid
End
The above function is an example
The requirement is when I TASL modify the ta1, first of all compare TA1 table TASL is greater than TA2 table Ta2ysh if greater than TA2 table Ta2ysh is not allowed to modify the operation, otherwise modify the TA2 table TA2SL and then modify TA1 in TASL