2013-08-26 100 views
0

我想SQLite的INSTEAD OF觸發器

ALTER TRIGGER [dbo].[trg_EliminoItems] 
ON [dbo].[PedidosEncabezado] 
INSTEAD OF DELETE 
AS 
BEGIN 

    SET NOCOUNT ON; 

    insert into HistPedidosEncabezado select * from PedidosEncabezado where PedidosID in (select PedidosID from deleted) 
    insert into HistPedidosItems select * from PedidosItems where PedidosID in (select PedidosID from deleted) 

    delete from PedidosItems where PedidosID in (select PedidosID from deleted) 
    delete from PedidosEncabezado where PedidosID in (select PedidosID from deleted) 

END 

這個轉換的Microsoft SQL Server觸發到SQLite的。

+0

而與此觸發你有什麼問題?該SQLite沒有'SET'語句,或其他? –

+0

我試圖在sqlite中創建相同的sql觸發器,但似乎sqlite不允許在僅在視圖中的表中創建觸發器。是對的嗎? –

+0

根據[文檔](http://www.sqlite.org/lang_createtrigger.html),這是正確的,但只適用於INSTEAD OF觸發器。 –

回答

0

的SQLite不允許INSTEAD OF觸發器表上,但你打算無論如何要刪除這些記錄:

CREATE TRIGGER trg_EliminoItems 
BEFORE DELETE ON PedidosEncabezado 
FOR EACH ROW 
BEGIN 
    INSERT INTO HistPedidosEncabezado 
     SELECT * FROM PedidosEncabezado WHERE PedidosID = OLD.PedidosID; 
    INSERT INTO HistPedidosItems 
     SELECT * FROM PedidosItems  WHERE PedidosID = OLD.PedidosID; 
    DELETE FROM PedidosItems   WHERE PedidosID = OLD.PedidosID; 
END; 
相關問題