大家看看这个触发器是干什么用的呀
CREATE TRIGGER post_insert ON dbo.post
FOR INSERT
AS
declare @parentid int
declare @topicusername varchar(50)
declare @postid int,@posttime datetime,@username varchar(50)
declare @forumname varchar(50)
declare @icon tinyint
declare @subject varchar(80)
declare @usejf bit
declare @topicRatings int
declare @replyRatings int
declare @jf int
declare @attachment bit,@encrypt bit
select @attachment=attachment,@encrypt=encrypt,@TopicRatings=isnull(topicRatings,0),@ReplyRatings=isnull(ReplyRatings,0),@forumname=inserted.forumname,@icon=inserted.icon,@subject=inserted.subject,@parentid=isnull(parentid,0),@postid=postid, @username=username,@posttime=posttime,@usejf=forum.jf from inserted inner join forum on inserted.forumname=forum.forumname
if (@parentid =0)
/*主题*/
begin
set @jf=@topicRatings
update post set attachmentfilename=(case when isnull(attachmentfilename,'')<>'' then convert(nvarchar(255),@postid)+'-'+attachmentfilename else null end),attachments=@attachment,encrypts=@encrypt,replycount=0,lastreplyusername=@username,lastreplyposttime=@posttime where postid=@postid
if (@usejf=1)
begin
update register set postcount=isnull(postcount,0)+1,jf=isnull(jf,0)+@jf where lower(username)=lower(@username)
end
update forum set lastpostusername=@username,topiccount=isnull(topiccount,0)+1,lastpostid=@postid,lastposttime=@posttime,lastposticon=@icon,lastpostsubject=@subject from forum where forumname=@forumname
end
else
/*跟贴*/
begin
set @jf=@replyRatings
update post set attachmentfilename=(case when isnull(attachmentfilename,'')<>'' then convert(nvarchar(255),@postid)+'-'+attachmentfilename else null end),attachments=@attachment,encrypts=@encrypt where postid=@postid
update post set attachments=isnull(attachments,0)+@attachment,encrypts=isnull(encrypts,0)+@encrypt,replycount=isnull(replycount,0)+1,lastreplyusername=@username,lastreplyposttime=@posttime where postid=@parentid
if (@usejf=1)
begin
update register set jf=isnull(jf,0)+@jf,postcount=isnull(postcount,0)+1 where lower(username)=lower(@username)
end
else
begin
update register set postcount=isnull(postcount,0)+1 where lower(username)=lower(@username)
end
update forum set lastpostusername=@username
,replycount=isnull(replycount,0)+1,
lastpostid=@parentid,lastposttime=@posttime,lastposticon=@icon,lastpostsubject=@subject from forum where forumname=@forumname
end