2016-06-16 2 views
0

오라클 트리거를 SQL 서버로 변환하는 것이 혼동 스럽습니다. 모든 포인터는 매우 높이 평가됩니다. 나는 "그때 삽입하는 경우"및 "SQL 서버에서 다음 업데이 트하는 경우"교체하는 방법을 잘 모르겠어요?오라클 트리거를 SQL 서버 트리거로 변환

create or replace trigger tg_ap 
    before insert or update of strno, strfac, strfacstreet, strfacstreet2 
    on AP 
    for each row 
    begin 
    if inserting then 
    :new.I_stat_ind:= 'Insert'; 
    end if; 
    if updating then 
     :new.I_stat_ind:= 'Update'; 
    end if; 
    END; 

답변

0

SQLServer는 작업이 업데이트, 삽입 또는 삭제인지 감지 할 때 약간 까다로운 작업을 수행합니다. 당신의 응답을

Create Trigger [name] on [table] Before Insert, Update As 
Begin 
declare @actionId int  


select @actionId = case 
         when i.id is not null and d.id is  null then 1 -- insert 
         when i.id is not null and d.id is not null then 2 -- update 
         when i.id is  null and d.id is not null then 3 -- delete 
        end   
    from  inserted i full join deleted d on d.id = i.id 

Your Code goes here 
+0

감사 :

내가 여기 당신의 트리거를 쓸 수 있지만하지 않습니다 당신이 현재 작업을 찾아 도움이 몇 가지 코드입니다. 삽입, 업데이트 대신 사용해야한다고 생각합니까? 내가 삽입하기 전에 SQL 서버에 업데이트가 없다는 것을 알았습니까? – wwidhoo

+0

당신 말이 맞아요. Before on MSSQL-Server와 같은 것은 없습니다. 나는 당신이 달성하기를 원하는 것을 모른다. 그러나 AFTER는 대부분의 경우 적절한 대안이다. – lokusking