0

我想转换这个 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。

4

1 回答 1

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;
于 2013-08-26T21:17:55.670 回答