码迷,mamicode.com
首页 > 数据库 > 详细

SQL Server论坛楼层计算触发器

时间:2015-06-08 13:00:45      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:

代码:

技术分享
USE suya_dev
GO

IF EXISTS(
    SELECT *
    FROM sys.triggers
    WHERE name = NBBS_Post_before_insert
)
    DROP TRIGGER BBS_Post_before_insert 
GO

CREATE TRIGGER BBS_Post_before_insert 
    ON BBS_Post
    FOR insert
AS 
BEGIN
   declare @Id int 
   declare @TopicId int
   declare @Floor int
   select @Id = Id from inserted
   select @TopicId = TopicId from inserted
   select @Floor = count(1) from BBS_Post where TopicId=@TopicId
   update BBS_Post set Floor=@Floor where Id=@Id
END
GO
View Code

 

SQL Server论坛楼层计算触发器

标签:

原文地址:http://www.cnblogs.com/s0611163/p/4560393.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!