开发者

Converting PL/SQL trigger to T-SQL

开发者 https://www.devze.com 2023-02-03 21:29 出处:网络
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

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
   开发者_如何学C        , :OLD.MT_MIKTAR
           , :NEW.MT_MIKTAR
           , SYSDATE
            );

EXCEPTION
   WHEN OTHERS
   THEN
      NULL;
END;


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消