Current location - Plastic Surgery and Aesthetics Network - Clothing company - Create SQL2008R2 trigger statement
Create SQL2008R2 trigger statement
Build a table that only uses four fields in a trigger.

Create a test table:

Create? Table? pubkszl

(gsdm? varchar(6),

kjnd? varchar(4),

dwdm? varchar( 10),

dqdm? Varchar( 1)) creates a trigger:

Create? Trigger? t_pubkszl

Open? pubkszl

After that? Insert, update

be like

Declare? @gsdm? varchar(6)

Declare? @kjnd? varchar(4)

Declare? @dwdm? varchar( 10)

Declare? @dqdm? varchar( 1)

begin

Choice? @gsdm=gsdm,@kjnd=kjnd,@dwdm=dwdm,@dqdm=dqdm? From where? inserted

What if? @ gsdm = ' 3 1 100 1 '? And then what? @kjnd='20 18 '? And then what? left(@dwdm, 1)='C '

begin

Settings? @dqdm=' 1 '

Update? pubkszl? Settings? dqdm=@dqdm? Where is it? gsdm=@gsdm? And then what? kjnd=@kjnd? And then what? dwdm=@dwdm

end

End test 1: insert a data that meets the trigger and a data that does not meet the trigger into the table;

Insert? Become? pubkszl? Values? ('3 1 100 1',' 20 18',' C023', empty)

Insert? Become? pubkszl? Values? ('3 1 100 1',' 20 18',' B023', null) The result is (trigger if the first item meets, and trigger if the second item does not meet):

Test 2: Change B023 of the second data to C00 1. Under normal circumstances, the dmdq of this data should also become 1:

Update? pubkszl? Settings? dwdm='C00 1 '? Where is it? Dwdm='B023' Result:

Then, according to your description, all the values have been referenced, so I set my table to varchar type. If it is numerical, it can be modified as appropriate.