首页 > 代码库 > 自己写的sql server触发器练练--高手请您跳过吧

自己写的sql server触发器练练--高手请您跳过吧

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(50),@beReplyedUid int,@beReplyedUname nvarchar(50),@replyTid int,@insertId int;
insert into bbsReplyTopic values(
@uid,@topicId,@Rcontent,@Rtime,@ccode,@uname,@beReplyedUid,@beReplyedUname,@replyTid
) select @insertId=@@identity
if(@insertId!=0)

select @topicId=topicId from inserted
update bbsTopic set replyCount=replyCount+1 where topicId=@topicId
print ‘您刚刚插入的id是‘+convert(varchar(10),@insertId)+‘,success‘

END

 

insert into bbsReplyTopic values(125,291,‘test‘,‘2014/10/6 00:00:00‘,‘chadao‘,‘zhangziyi‘,125,‘zhangziyi‘,0)

自己写的sql server触发器,当回帖帖子被回复时,帖子的回复数量字段就加1

测试成功!

 

自己写的sql server触发器练练--高手请您跳过吧