MS-SQL更新触发器(多行),没有游标? [英] MS-SQL Update Trigger (multiple rows), without a Cursor ?

查看:110
本文介绍了MS-SQL更新触发器(多行),没有游标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

是否有可能创建这样的触发器:

Hello,

is there any chance of creating a trigger like this one:

CREATE TRIGGER tri_Test ON TESTTABLE FOR UPDATE NOT FOR REPLICATION AS
    SET NOCOUNT ON
        BEGIN

            DECLARE @Field1 varchar(31)
            DECLARE @Field2 bigint

            SELECT @Field1 = Field1 FROM inserted;
            SELECT @Field2 = Field2 FROM inserted;

            INSERT INTO NEWTABLE (Field1,Field2)
            VALUES (@Field1, @Field2)

        END
GO



插入"中的多个行,但不使用使用游标?
我在Google上搜索了很多,并玩了WHILE和@@ rowcount,但找不到解决方案.

一个样本会很好.



我的目标不是镜像"表.


谢谢



for multiple Rows in "inserted" but without the use of a cursor?
I googled a lot and played with WHILE and @@rowcount but could not find a solution yet.

A sample would be nice.



my goal is not to "mirror" the tables.


thank you

推荐答案

为什么你不能只说
why cant you just say
insert into newtable( field1,field2) select field1,field2 from inserted


这篇关于MS-SQL更新触发器(多行),没有游标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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