Set ANSI_NULLS on
SET QUOTED_IDENTIFIER ON
Go
ALTER TRIGGER [Insertreplytoic]
on [dbo]. [Bbsreplytopic]
After insert
As
BEGIN
--set NOCOUNT on;
--Insert statements for trigger here
declare @uid int, @topicId int, @Rcontent nvarchar (max), @Rtime datetime, @ccode varchar (max)
, @uname nvarchar, @beReplyedUid int, @beReplyedUname nvarchar (), @replyTid int, @insertId int;
INSERT into bbsreplytopic values (
@uid, @topicId, @Rcontent, @Rtime, @ccode, @uname, @beReplyedUid, @beReplyedUname, @replyTid
) select @[email Protected] @identity
if (@insertId!=0)
Select @topicId =topicid from inserted
Update bbstopic set replycount=replycount+1 where [email protected]
print ' The ID you just inserted is ' +convert (varchar), @insertId) + ', Success '
END
INSERT into bbsreplytopic values (125,291, ' Test ', ' 2014/10/6 00:00:00 ', ' Chadao ', ' Zhangziyi ',, ' Zhangziyi ', 0)
Your own SQL Server trigger, when the reply post is replied, the number of replies to the Post field is added 1
Test success!
Write your own SQL Server triggers practice--Master please skip it