Misalnya di table Customer dibuat trigger, supaya otomatis nambah record ke table TableCust. Nah, trigger ini dipasang di table Customer, yg punya field CustCode dan Custname. Di sini ada proses pengecekan, apakah di table tujuan, sudah ada kode & nama yang sama.
ALTER Trigger [dbo].[UpdateTableCust]
On [dbo].[Customer]
For Insert,Update
As
Declare @Code As Varchar(50);
Declare @Name As Varchar(50);
Select @Code = i.CustCode From inserted i;
Select @Name = i.CustName From inserted i;
If @Code is not Null
Begin
If Not Exists(Select CustCode From TableCust Where CustCode = @Code and CustName =@Name)
Begin
Insert Into TableCust(CustCode,CustName) Values (@Code,@Name)
On [dbo].[Customer]
For Insert,Update
As
Declare @Code As Varchar(50);
Declare @Name As Varchar(50);
Select @Code = i.CustCode From inserted i;
Select @Name = i.CustName From inserted i;
If @Code is not Null
Begin
If Not Exists(Select CustCode From TableCust Where CustCode = @Code and CustName =@Name)
Begin
Insert Into TableCust(CustCode,CustName) Values (@Code,@Name)
End
No comments:
Post a Comment