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

时间:2011-01-11 17:50:39

标签: tsql plsql

我不擅长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;

1 个答案:

答案 0 :(得分:1)

可能类似

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;

TSQL中没有行触发器,序列也不会出现在下一个版本之前,因此我假设ID_DEPO_STOK_IZLEME将是identity列。