Home > database >  SQL insert trigger example
SQL insert trigger example

Time:09-25

Create the trigger [dbo] [Tig_dfMES_Insert]
On [dbo] [dfMES] after insert, insert type
As
Declare @ vis varchar (8)
Declare @ newvid varchar (20)
- if you insert VID code is empty or NULL and VIN code is not NULL,
If (((select VID code from inserted)='or (select VID code from inserted) is NULL) and (select VIN code from inserted)!=' 'and (select VIN code from inserted) is not NULL)
The begin
The SET @ vis=(select right (VIN code, 8) from inserted) - get after eight vis
The set @ newvid=(select TOP 1 VID code from dbo. Dfmes_bak WHERE VIN code like '%' + @ vis) - get VID code
The UPDATE dfMES SET VID code=@ newvid WHERE VID code=(SELECT VID code FROM inserted) - UPDATE statement
End
The else
The begin
Insert into dbo. Dfmes_bak select * from inserted, inserted into the table data
End
  • Related