Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Insert trigger

Author  Topic 

shajimanjeri
Posting Yak Master

179 Posts

Posted - 2008-02-03 : 09:30:40
Dear all,

I have a table named Messages with fields
Id numeric
SmsBody varchar(4000)
mobilenumber varchar(15)
Status char(1).
and also there is another table named MsgHistory with fields
Id numeric
MsgId numeric -- (will be the Id from table Messages)
SmsBody varchar(4000)
Status char(1).

I need to work a trigger if any new message (record) is inserted into table Messages, at the same time the trigger should execute to insert MsgId and SmsBody to table MsgHistory from table Messages.

How I can write trigger for this?

with regards
Shaji



visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-02-03 : 09:43:19
CREATE Trigger MessageAudit
ON Messages
AFTER INSERT
AS
INSERT INTO MsgHistory(MsgId,SmsBody,Status)
SELECT i.MsgId,i.SmsBody,i.Status
FROM INSERTED
GO
Go to Top of Page
   

- Advertisement -