1
I’m creating a Rigger that the moment you delete an employee she changes the status from 1 (active) to 0 (inactive) then save this change in a table (employees dismissed) to access if you need, however, I’m in trouble. As soon as I try to create Trigger SQL Server informs the following message
Message 213, Level 16, State 1, Trigfunctionemitted Procedure, Line 23 Column name or number of values provided 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 in the following link
Andrey, thanks for the help in editing the post.
– Diogo Malvezzi
Employee check dismissed, if there is the table and if the columns are the same as employees plus a date column, the error seems to be there.
– Motta
Thanks Motta! Thank you very much!
– Diogo Malvezzi