插入触发器MS SQL 2008 [英] Insert Trigger MS SQL 2008

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

问题描述

大家好,

我需要实现一个触发器,该触发器在表A中发生插入时触发.与此同时,我还想将此插入的数据复制到另一个表B中.

我该怎么办?

请帮帮我.

在此先感谢.

Hi All,

I need to implement a trigger which triggers when an insert occurs in table A. At the same time I also want to copy this inserted data into another table B.

How can I do that?

Please help me.

Thanks in Advance.

推荐答案

这是解决方案

Here is the Solution

CREATE Trigger trg_A
ON A
FOR INSERT
AS

Begin

Declare @Col1 int, @Col2 varchar(20)

Select 
@Col1=i.col1,
@Col2=i.col2
FROM Inserted i

INSERT INTO B VALUES(@Col1,@Col2)

End


开始 ^ ].在发布此信息之前,您应该先尝试自己做一些事情,然后告诉我们您已经采取了哪些措施来帮助自己,遇到了哪些问题等.
Start here[^]. You should try and work something out for yourself before posting here and tell us what it is you have done to help yourself, what issues you came up against, etc.


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

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