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