您的位置:首页 > 博客中心 > 数据库 >

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

时间:2022-03-14 00:37

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

测试成功!

 

热门排行

今日推荐

热门手游