将 PL/SQL 触发器转换为 T-SQL

发布于 2024-10-11 15:09:54 字数 606 浏览 2 评论 0原文

我不擅长T-SQL。下面的触发器如何进入T-SQL?因为每个在 T-SQL 中都不起作用。

CREATE OR REPLACE TRIGGER DSS.TRG_DEPO_STOK_IZLEME
   BEFORE INSERT OR UPDATE
   ON DSS.CR_DEPO_STOK FOR EACH ROW
BEGIN

INSERT INTO CR_DEPO_STOK_IZLEME
            (ID_DEPO_STOK_IZLEME
           , ID_DEPO_STOK
           , MT_MIKTAR_ESKI
           , MT_MIKTAR_YENI
           , EKLEME_TARIHI
            )
     VALUES (SEQ_ID_DEPO_STOK_IZLEME.NEXTVAL
           , :NEW.ID_DEPO_STOK
           , :OLD.MT_MIKTAR
           , :NEW.MT_MIKTAR
           , SYSDATE
            );

EXCEPTION
   WHEN OTHERS
   THEN
      NULL;
END;

I am not good at T-SQL. How can does following trigger into T-SQL? For each doesn't work in T-SQL.

CREATE OR REPLACE TRIGGER DSS.TRG_DEPO_STOK_IZLEME
   BEFORE INSERT OR UPDATE
   ON DSS.CR_DEPO_STOK FOR EACH ROW
BEGIN

INSERT INTO CR_DEPO_STOK_IZLEME
            (ID_DEPO_STOK_IZLEME
           , ID_DEPO_STOK
           , MT_MIKTAR_ESKI
           , MT_MIKTAR_YENI
           , EKLEME_TARIHI
            )
     VALUES (SEQ_ID_DEPO_STOK_IZLEME.NEXTVAL
           , :NEW.ID_DEPO_STOK
           , :OLD.MT_MIKTAR
           , :NEW.MT_MIKTAR
           , SYSDATE
            );

EXCEPTION
   WHEN OTHERS
   THEN
      NULL;
END;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冷弦 2024-10-18 15:09:54

可能类似于

CREATE TRIGGER DSS.TRG_DEPO_STOK_IZLEME
   ON DSS.CR_DEPO_STOK
   AFTER INSERT, UPDATE
AS   
BEGIN

INSERT INTO CR_DEPO_STOK_IZLEME
            (ID_DEPO_STOK
           , MT_MIKTAR_ESKI
           , MT_MIKTAR_YENI
           , EKLEME_TARIHI
            )
SELECT       i.ID_DEPO_STOK
           , d.MT_MIKTAR
           , i.MT_MIKTAR
           , GETDATE()
FROM INSERTED i FULL OUTER JOIN DELETED d ON i.pk = d.pk            

END;

There are no row triggers in TSQL,序列也不会出现,直到下一个版本,所以我假设 ID_DEPO_STOK_IZLEME 将是一个 identity 列。

Probably something like

CREATE TRIGGER DSS.TRG_DEPO_STOK_IZLEME
   ON DSS.CR_DEPO_STOK
   AFTER INSERT, UPDATE
AS   
BEGIN

INSERT INTO CR_DEPO_STOK_IZLEME
            (ID_DEPO_STOK
           , MT_MIKTAR_ESKI
           , MT_MIKTAR_YENI
           , EKLEME_TARIHI
            )
SELECT       i.ID_DEPO_STOK
           , d.MT_MIKTAR
           , i.MT_MIKTAR
           , GETDATE()
FROM INSERTED i FULL OUTER JOIN DELETED d ON i.pk = d.pk            

END;

There are no row triggers in TSQL also sequences will not appear until the next version so I have assumed that ID_DEPO_STOK_IZLEME will be an identity column.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文