1
I have a SQL Server registration table, I have a column that shows the status of this registration ('A','I','S','C')
.
I created a field with name Update_data
, that you will receive a datatime every time the customer changes the status of the registration. This is also true for an Insert.
I’m having doubts because I never created a Trigger in sql server.
Ex: from my table
ID | Processo | status | Update_data
1 | A33 | A | null
2 | A34 | I | null
3 | A55 | A | null
I could not advance in the following example below Trigger:
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
At the end, it will be updated with the current date only if there is modification or insertion in the situation field.
Which column uniquely identifies each row?
– José Diz