Creating Trigger to change status as soon as deleting employee

1

I'm creating a trigger that when I delete an employee, it changes the status from 1 (active) to 0 (inactive), then save this change to a table (public employees) to access if need be, however, I'm having problems. As soon as I try to create the trigger SQL Server informs the following message

  

Message 213, Level 16, State 1, Procedure TrigFuncionarioDemitido, Line 23   The column name or number of supplied values does not match the table definition.   Citation

CREATE TRIGGER TrigFuncionarioDemitido
ON funcionarios
INSTEAD OF  DELETE
AS
BEGIN
       Begin Transaction F1
       -- DECLARAR UMA VARIมVEL
     DECLARE @id  INT
     -- ATRIBUIR VALOR A VARอAVEL @id
       SELECT @id =
                            (
                  SELECT D.id
                  FROM    deleted             AS D
                )
    -- 1) fazer o UPDATE na tabela de Funcionแrio
    -- atualizar o Status
    UPDATE funcionarios
    SET Status = 0
    WHERE  id = @id

    -- 2) FAZER UMA INSERวรO DO FUNCIONARIO DEMITIDO
    -- PARA A TBFUNICONARIO DEMITIDO
    INSERT INTO funcionariosdemitidos
    SELECT f.* , GETDATE ()
    FROM funcionarios AS f
    WHERE id = @id
    IF (@@ERROR = 0)
      begin
         commit transaction f1
       print 'Registro atualizado com sucesso'
     end
    ELSE
       begin
         rollback transaction f1
       print 'Registro nใo atualizado'
       end

END

Complete bank code and trigger on next link

link

    
asked by anonymous 25.05.2014 / 20:00

1 answer

1

After observing Motta, I added the date field in the table, and it worked.

  

Checked officials, if there is a table and if the columns are   the same of officials plus a date column, the error seems to be   there. - Motta

In the code I was adding the getdate (), however, in the publicly-issued table there were no such lines. After that, the trigger ran certina.

Thank you!

    
25.05.2014 / 22:09