Hi folks,
I'm new to triggers. I'm looking to create a trigger which will track every account which has been created through an INSERT or changed through an UPDATE. To do so, I created this:
Create Trigger [dbo].[TrackAccountChanges] on [dbo].[Clients] After Insert, Update AS
BEGIN
DECLARE @Account int
SET NOCOUNT ON;
Select @Account = Account from inserted
BEGIN
Insert Into AccountChanges Select CURRENT_TIMESTAMP, @Account
End
End
But if I run, say, "Update clients set Active = 1 where Account in (1, 2, 3)" which affects 3 accounts, the trigger result appearing in the AccountChanges table is:
ID EventDateTime Account
105760 2021-05-28 10:48:17.7900000 1
when what I'm looking for is a trigger which will show all updated records, i.e.:
ID EventDateTime Account
105760 2021-05-28 10:48:17.7900000 1
105760 2021-05-28 10:48:17.7900000 2
105760 2021-05-28 10:48:17.7900000 3
What am I missing? Thanks!