Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Administration
 sorting records depending on the time of insertion

Author  Topic 

Nischith
Starting Member

1 Post

Posted - 2011-08-01 : 02:29:51
Hi,
How do I sort the records of a table depending on the time of insertion of records using "order by". Does the database store any information related to the time of insertion or a timestamp which indicates when the record was inserted. If so can I use it in in a query like :

select * from <table name> order by <some attribute>;

please guide me if any idea about the topic.
Another way is to insert a timestamp myself in the table but that is again a tedious job because the servers which i'm using to run jsp page and the database are different and I doubt the synchronization between the both.

Thanks in advance.

Nischith

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-08-01 : 02:36:00
quote:
Does the database store any information related to the time of insertion or a timestamp which indicates when the record was insertedp

Nope. You have to add a datetime column in the table and default it to getdate()




KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-08-01 : 04:41:31
even an identity column in table will make sure on insertion they get values sequential and you can order based on them also while retrieving

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -