October 17, 2011 at 9:43 am
Hello All,
I have a application logging table with a datetime field that defaults to getdate(). I do present these logs to end users and when I do I want to order the logged events so the user sees the sequence in which they actually occurred.
Some of my logged events are getting the same data and time and as such I can't tell which came first.
I have added an identity field to be used in an ORDER BY clause. This works but I am concerned I have added a lot of overhead just to order the results properly.
Any way I can do this without the identity column?
thanks...
October 17, 2011 at 9:54 am
I wouldn't worry about the identity column causing "overhead." I think that is the best way to accomplish what you are looking for. That being said... It is possible for these to still become inserted in an order that is not "real." How important is it that these are in an exact order?
Thanks,
Jared
Jared
CE - Microsoft
October 17, 2011 at 10:00 am
>> How important is it that these are in an exact order?
Its not critical to the functioning of the app. Its really a matter of understandability to the end user if they need to review the logs.
Can the identity numbers get out of sequence even if I am inserting one record at a time using separate insert statements?
October 17, 2011 at 10:04 am
It really depends on how your inserts are being called. Are different stored procedures inserting the same data? Are your getdate() sometimes being stored in a temp table before getting inserted? I think the closest you can get here is by doing what you are doing, understanding that there may be cases where something will be out of order from the way it "seemed" to be executed.
Thanks,
Jared
Jared
CE - Microsoft
October 20, 2011 at 8:49 am
One more thought! Have you tried using SYSDATETIME() instead of GETDATE()?
SELECT GETDATE();
GO
SELECT SYSDATETIME();
GO
Quite a difference!
Jared
Jared
CE - Microsoft
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply