日期:2014-05-17 浏览次数:20602 次
CREATE TRIGGER [dbo].[tr_ps]
ON [dbo].[ps]
AFTER INSERT,DELETE,UPDATE
AS
begin
SET NOCOUNT ON;
UPDATE p SET closed=CASE WHEN a.closed=1 THEN 0 ELSE 1 end
FROM
(
SELECT id,MAX(CASE WHEN closed=0 THEN 1 ELSE 0 END) closed
FROM ps
WHERE id IN
(
SELECT id FROM INSERTED
UNION
SELECT id FROM DELETED
)
GROUP BY id
) a
WHERE p.id=a.id
end