Monday, November 16, 2009

SQL - trigger

[Sample of trigger for "inserted"]

Create trigger MMS_insert_dup on t_mms_mo_mms_send_history for insert
as
begin
declare @TxID bigint
declare @MMSTitle nvarchar(50)
select @TxID=TransactionID,
@MMSTitle = MMSTitle
from inserted
insert XXX..XXX(TransactionID, MMSTitle)
values (@TxID, @MMSTitle)
end


Sample of trigger for "updated" (There is no "Updated" table)
Create trigger MMS_update_dup on t_mms_mo_mms_send_history for update
as
begin
declare @TxID bigint
declare @MMSTitle nvarchar(50)
select @TxID=TransactionID,
@MMSTitle = MMSTitle
from inserted
update XXX..XXX
set
MMSTitle = @MMSTitle
where TransactionID = @TxID
end

No comments: