Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

what is the latest data just inserted?

Status
Not open for further replies.

babeo

Technical User
Mar 30, 2000
398
CA
Hello,

could some one let me know how to check for the latest data/row in a database. I want to know when or what date/time a data just inserted into a database.
Thanks
 
Not possible unless you set something up to record it.

You can use triggers to set the datetime of an insert or updates.
If you just want the order of insert then an identity column would do it.
If you want the order of insert/update then a timestamp column (which is nothing to do with a date or time).

======================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
 
You could add a column of datatype DATETIME and set the DEFAULT value to getdate()

When you insert SQL will update that column with the date and time that record was inserted.
 
Hi pkailas,

It's a good to know the exact date of data is inserted, and not good idea because I have to design a database with more space to hold on this extra column. Oracle allows to check the latest row, but I don't know how to find a way to check for Sybase !
Thanks anyway.
 
I agree, however if your DB of choice doesn't provide you with the same features as Oracle, you have to design it to provide you with that.

FYI, how do you think Oracle provides you with that information? They would have to store it and that takes space. So, while you think you are designing a more compact DB, you really aren't.
 
Uhm! That's a good point, I did not think about it.
Should I concern anything if I add 1 more column to the current table?
Thanks
 
You shouldn't have. However, if it's a large table containing a lot of data, create the column allowing nulls and save it first. Then change it to not allow nulls and set the default value to getdate()

Otherwise you may end up setting all the dates to now. Or it may not even let you save it.
 
If you are worried about the size of the field ... choose a smalldatetime instead of using the full datatime datatype.

Thanks

J. Kusch
 
If space is a premium, and you don't need to know the exact date but only the order in which the data was added, you might consider using an Identity field. It's only four bytes and maintains itself.
 
Thanks everyone for rich tips.
I now can think what I want to do.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top