[英]How to convert DB2 trigger to SQL Server?
I am converting some DB2 triggers to SQL Server.我正在将一些 DB2 触发器转换为 SQL 服务器。 One of them shown here I am struggling with it, Conversion tried at certain extend but seems not good enough to work out.
这里展示的其中一个我正在努力解决,Conversion 在一定程度上尝试过,但似乎还不够好,无法解决。
Trigger execute before an update or insert and selecting the value of column PDE_KEY
based on Select
statement in brackets with where clause before written to the database.在更新或插入之前触发执行,并在写入数据库之前根据括号中的
Select
语句和 where 子句选择列PDE_KEY
的值。
Need help.需要帮忙。
DB2 trigger DB2 触发器
CREATE OR REPLACE TRIGGER "TDC" BEFORE
INSERT
ON
"DECL_CONSIGNMENT" REFERENCING NEW AS NEW FOR EACH ROW NOT SECURED SET
NEW.PDE_KEY = (
SELECT
D.PDE_KEY
FROM
DECL D
WHERE
D.DE_KEY = NEW.DE_KEY)
SQL Server conversion of this trigger (my attempt): SQL 这个触发器的服务器转换(我的尝试):
CREATE TRIGGER [TDC]
ON [DECL_CONSIGNMENT]
INSTEAD OF INSERT
AS
BEGIN
DECLARE @PDE_KEY BIGINT
SET NOCOUNT ON
SELECT
@PDE_KEY = D.PDE_KEY
FROM
DECL D
WHERE
D.DE_KEY = (...work upto here)
END
An instead of
trigger must explicitly execute the dml needed. instead of
触发器必须显式执行所需的 dml。
REATE TRIGGER [TDC]
ON [DECL_CONSIGNMENT]
INSTEAD OF INSERT
AS
BEGIN
SET NOCOUNT ON;
INSERT INTO [DECL_CONSIGNMENT] (a, b, .. PDE_KEY, ..)
SELECT a, b, .. (
SELECT
D.PDE_KEY
FROM
DECL D
WHERE
D.DE_KEY = i.DE_KEY),
..
FROM inserted i;
END
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.