We are having a very strange problem whereby when calling GETUTCDATE()
the returned value is very slightly earlier in the second statement than the first. The scenario we have is the following:
We insert into a table to track a users current status, this table has a trigger on which inserts into an associated history table of the users past statuses with a
DATETIME
field and the insert callsGETUTCDATE()
Once this is done we have another table with an associated record we insert into calling
GETUTCDATE()
which tracks which part updated the user status.
So the flow would be:
- Insert into
UserStatuses
- Trigger fires on
UserStatuses
table inserting intoUserStatusesHistory
callingGETUTCDATE()
- Then we insert into
OwningStatuses
table callingGETUTCDATE()
We are finding that on some occasions the DATETIME
on the UserStatusesHistory
is after the DATETIME
on the OwningStatuses
table.
How can this be when the GETUTCDATE()
on the OwningStatuses
is called after the GETUTCDATE()
for the UserStatusesHistory
table?
In some scenarios are triggers run asynchronously? (I can't believe this as it's against everything I have read and we are not using any service brokers).
Is it possible the GETUTCDATE()
is cached at the beginning of the procedure on some occasions and this cached value isn't carried into the trigger?