大家看看这个触发器是干什么用的呀

shiguangxin 2004-11-22 03:24:35
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

...全文
81 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
aliren 2004-11-22
  • 打赏
  • 举报
回复
恭喜楼主问题解决了
shiguangxin 2004-11-22
  • 打赏
  • 举报
回复
问题解决了
shiguangxin 2004-11-22
  • 打赏
  • 举报
回复
说什么也调不过去了呀
也不知道是那里错了呀 5555
shiguangxin 2004-11-22
  • 打赏
  • 举报
回复
各位老大帮帮忙呀
小弟都快晕死了呀
chenyuandxm 2004-11-22
  • 打赏
  • 举报
回复
你要知道干什么用的干吗?
davorsuker39 2004-11-22
  • 打赏
  • 举报
回复
晕了
shiguangxin 2004-11-22
  • 打赏
  • 举报
回复
我头更晕呀
调试别人的程序 555~~~~
vinsonshen 2004-11-22
  • 打赏
  • 举报
回复
哈哈, 看得有点头晕了~~
shiguangxin 2004-11-22
  • 打赏
  • 举报
回复
插入数据时报错
"parentid " 不明确

34,591

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧