Click here to Skip to main content
15,890,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I need such trigger that insert record on other database when record inserted in itself.
Posted

1 solution

USE [ZCLS_MM]
GO
/****** Object: Trigger [dbo].[TriggerOnInsert] Script Date: 09/19/2012 11:12:28 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =========================================================
-- Author: Ravi Sharma
-- Create date: 10/10/2012
-- Description: Trigger to auto insert into other database
-- =========================================================
ALTER TRIGGER [dbo].[TriggerOnInsert]
ON [ZCLS_MM].[dbo].[MessageTransaction]
FOR INSERT


AS
BEGIN

select distinct i.MessageID,i.ChannelNo,i.ExtensionNo,i.IPAddress,i.MessageFileName,i.MessageDate,i.CallerId,i.InOutFlag,
i.PlayPath,i.Information from inserted i

declare
@MessageID numeric(10, 0),
@ChannelNo numeric(3, 0),
@ExtensionNo nvarchar(50),
@IPAddress nvarchar(50),
@MessageFileName nvarchar(255),
@MessageDate datetime,
@CallerId nvarchar(50),
@InOutFlag int,
@PlayPath nvarchar(255),
@Information char(25)

select @ChannelNo=i.ChannelNo from inserted i;
select @ExtensionNo=i.ExtensionNo from inserted i;
select @IPAddress=i.IPAddress from inserted i;
select @MessageFileName=i.MessageFileName from inserted i;
select @MessageDate=i.MessageDate from inserted i;
select @CallerId=i.CallerId from inserted i;
select @InOutFlag=i.InOutFlag from inserted i;
select @PlayPath=i.PlayPath from inserted i;
select @Information=i.Information from inserted i;

Insert into ZCLS.dbo.MessageTransaction(ChannelNo,ExtensionNo,IPAddress,MessageFileName,MessageDate,CallerId,InOutFlag,PlayPath,Information) values
(@ChannelNo,@ExtensionNo,@IPAddress,@MessageFileName,@MessageDate,@CallerId,@InOutFlag,@PlayPath,@Information)

PRINT 'AFTER INSERT trigger fired.'

END
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900