触发器的问题..
比如一个论坛..
如果你回了一张贴,就得把那个主题的回贴数量+1,然后再把那个论坛总回贴数量+1..
我建立了两个触发器.
CREATE TRIGGER Post_Reply
ON [post]
FOR INSERT
AS
UPDATE T SET
threadReplyCount = T.threadReplyCount + 1 //把主题的回贴数量+1
FROM Thread AS T INNER JOIN Inserted AS I
ON T.threadId = I.threadId
CREATE TRIGGER Add_Reply
ON [post]
FOR INSERT
AS
UPDATE F SET
forumPostCount = F.forumPostCount + 1 //这里把论坛的总回贴数量+1
FROM forum AS F INNER JOIN Inserted AS I INNER JOIN thread AS T
ON T.threadId = I.threadId AND T.forumId = F.forumId
第一个触发器创建成功了,但是第二个触发器的
ON T.threadId = I.threadId and T.forumId = F.forumId
有错误...可是我看了半天,就是找不到问题,怎么回事呢?
出错信息:
Server: Msg 170, Level 15, State 1, Procedure Add_Reply, Line 8
第 8 行: 'forumId ' 附近有语法错误。
------解决方案--------------------FOR INSERT
AS
UPDATE F SET
forumPostCount = F.forumPostCount + 1
FROM forum AS F, Inserted AS I , thread AS T
where T.threadId = I.threadId AND T.forumId = F.forumId
改这样try
倒是没有看到过两个内连接连用的。O.o