MSSQL – Trigger for update field copy form others field.

This script is useful when you want update field with a same value from other field.

CREATE TRIGGER[dbo].[trigger_item_download]
ON [dbo].[ILINK_ITEM_DOWNLOAD]
AFTER INSERT
AS
BEGIN
IF EXISTS (SELECT *
FROM inserted)
BEGIN
UPDATE o
SET o.IM_INTERFACE_RECORD_ID = i.RecordNo
FROM [ILINK_UT].[dbo].[ILINK_ITEM_DOWNLOAD] o,
inserted i
WHERE o.RecordNo = i.RecordNo
END
END
GO

The query above mean if you insert into ILINK_ITEM_DOWNLOAD recordNo = 1

then, trigger will update on that rows, field IM_INTERFACE_RECORD_ID = 1