Sending data from one table to another with the deleted command

4

I'm creating this trigger in SQL Server , but I'm not getting the id to send the data to another table and delete this table.

CREATE TRIGGER MoveComprador
ON comprador
INSTEAD OF DELETE
AS
BEGIN
  SELECT * INTO bk_comprador FROM comprador WHERE comprador.codigo = deleted;
END
GO
    
asked by anonymous 19.06.2015 / 06:31

1 answer

2

You need to set the "affected" column in the DELETE you want to get.

In this case, use the statement "deleted. YourColumn".

Below is a T-SQL script for you to adapt to your needs:

CREATE TRIGGER MoveComprador
ON comprador
INSTEAD OF DELETE
AS
BEGIN
  DECLARE @ID  int
  SELECT @ID = deleted.id FROM deleted;

  INSERT INTO TB_LOG (CD_REGISTRO, NM_ACAO) VALUES (@ID, 'EXCLUIDO');

END

GO

For more information see:

link

    
19.06.2015 / 14:36