在SQL SERVER 2008中创建触发器 [英] CREATE TRIGGERS IN SQL SERVER 2008

查看:78
本文介绍了在SQL SERVER 2008中创建触发器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望为两个表创建触发器我的表是子语句和子通讯历史



子语句历史是子语句表的重复表

我的要求当我将数据插入子通知表时,然后将子通讯表更新为

新记录并将旧记录插入子通讯表

i want create trigger for two tables my tables are subcomment and subcommenthistory

subcomment history is duplicate table of subcomment table
my requirement is
when i insert the data into subcomment table then subcomment table is update with
new record and insert old records into subcommenthistory table

推荐答案

你没有提到确切的问题,所以简单回答。您需要创建一个触发器,使用已删除的表来查询旧值。



所以像

You didn''t mention the exact problem, so a brief answer. You would need to create a trigger which uses the deleted table to query the old values.

So something like
CREATE TRIGGER ABC ON subcomment
AFTER UPDATE, DELETE 
AS
BEGIN
   INSERT INTO subcommenthistory
   SELECT ...
   FROM DELETED;
END;



更多信息:

- http://msdn.microsoft.com/en-us/library/ms189799.aspx [<一个href =http://msdn.microsoft.com/en-us/library/ms189799.aspxtarget =_ blanktitle =新窗口> ^ ]

- http://msdn.microsoft.com/en-us/library/ms191300.aspx [ ^ ]

这篇关于在SQL SERVER 2008中创建触发器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆