触发显示两行受影响的T-SQL
本文关键字:两行 影响 T-SQL 显示 | 更新日期: 2023-09-27 18:14:28
我只想获得一次数据。怎么做呢?例如,只从第一个动作
表myTABLE1
(
NAME,
SURNAME,
USERNAME,
USERDATE
)
第一个动作到MyTABLE1
INSERT INTO MyTABLE1
SELECT NAME, SURNAME FROM MyTABLE2
对MyTABLE1的第二个动作
CREATE TRIGGER example on MyTABLE1 AFTER INSERT
AS
UPDATE MyTABLE1
SET USERNAME = 'sysUser1212' and USERDATE = '2004-09-02 00:00:00.000'
我得到两行影响到MyTable3,但我想只得到一次
CREATE TRIGGER example2 on MyTABLE1 FOR INSERT UPDATE DELETE
AS
INSERT INTO MyTABLE3
SELECT NAME, SURNAME, USERNAME, USERDATE
from inserted
Create as INSTEAD OF trigger .
在插入的时候,你可以把USERNAME替换为'sysUser1212',把USERDATE替换为'2004-09-02 00:00:00.000'。
CREATE TRIGGER examplex on MyTABLE1 INSTEAD OF INSERT
AS
INSERT MyTABLE1 (USERNAME, USERDATE, NAME, SURNAME)
SELECT
'sysUser1212'
, '2004-09-02 00:00:00.000'
, NAME
, SURNAME
FROM inserted
-- The following disapear
/*
CREATE TRIGGER example on MyTABLE1 AFTER INSERT
AS
UPDATE MyTABLE1
SET USERNAME = 'sysUser1212' and USERDATE = '2004-09-02 00:00:00.000'
--*/