2011-01-11 23 views
1

我不擅長T-SQL。如何觸發到T-SQL中?對於每個在T-SQL中不起作用。將PL/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

直到下一個版本,TSQL中沒有序列。您是否使用標識列?還有什麼`當其他人'做什麼? – 2011-01-11 17:54:35

+0

是的,我正在使用標識列。其他不重要,不需要轉換 – mcb 2011-01-11 19:01:11

回答

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列。