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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to find NEWLY inserted Data

Status
Not open for further replies.

rasprer

Programmer
Feb 12, 2004
102
0
0
US
I have a huge problem. I need to find a way to retrieve 'Newly' created records from the table. The table DOES NOT have any datetime fields I can reference nor do I have a field that is defined as an identity column.

Is there anyway that I can retrieve these new records..Say..I write a program to find all the records in the table at 2:pm. Then I stop the program, and run it again at 3:pm. Now I need all the data from 2:pm - 3:pm.

Note...I cannot create any fields in the database nor any table.

Please assist...
 
can u use "select top 10 * from <table> where ..."...

Or "top <whatever rows u want> * from <table> where.."

Or, can u you relate this table to another table that has datetime or identity?
 
Selecft Top ...

will not give you the latest records in most cases.
The only case where it will is where there is a key that gives indication of the cronilogical order of records is available.

This could be an indentity field, DateTime that is defaulted to (GETDATE()) or a TIMESTAMP column.

Basically the table has to be designed to have some column that holds that information. If it doesn't you can't be assured the order.

With a heap you can't guarentee that the last records are the most recently added unless you never delete records. With tables that are in a clustered index there is no hope unless agian you have the data from above.



Hope I've been helpful,
Wayne Francis

If you want to get the best response to a question, please check out FAQ222-2244 first
 
I've never tried this but it's just a thought. Would the transaction log have what you need?
 
One possible solution would be at the 2pm point add
an identity column into the table

E.G

ALTER TABLE [tablename]
ADD [NewColumnName] int IDENTITY(1,1)

This will give all the columns a number starting at 1 upwards the next row inserted into the table will get an incrementle number all you need to do is find the max(NewColumnName) at each point 2pm , 3pm etc then you can select data between points using that column

obviosuly i recommend you test this first to see if it would work for you, I dont know how datas imported into the table and an extra column might effect this process.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top