SQLite INSTEAD OF TRIGGER

时间:2013-08-26 14:54:19

标签: sql-server sqlite triggers

我想转换此Microsoft SQL Server触发器

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

进入SQLite。

1 个答案:

答案 0 :(得分: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;