I have a SQL Server database table, I have a column that shows the status of that database ('A','I','S','C')
.
I created a field named Update_data
, which will receive a datatime every time the client changes the registration status. This also applies to an insert.
I'm in doubt, because I've never created a Trigger on a sql server.
Ex: from my table
ID | Processo | status | Update_data
1 | A33 | A | null
2 | A34 | I | null
3 | A55 | A | null
I was unable to proceed in the following example below:
CREATE TRIGGER atualizaData
ON cadastro
AFTER INSERT,UPDATE
AS
IF INSERT OR UPDATE(status)
BEGIN
UPDATE cadastro
SET Update_data = GETDATE()
WHERE id = id_que_foi_modifica/inserida
END
In the end, it will be updated with the current date only if there is modification or insertion in the situation field.