Re: SQL question: How to periodically read the last 'n' rows of a simple table?
From: Louis Davidson (dr_dontspamme_sql_at_hotmail.com)
Date: 02/03/05
- Next message: oj: "Re: Backup database without stored procedures"
- Previous message: Gary K: "HOST_NAME length"
- In reply to: Hamelech Al Hakol: "Re: SQL question: How to periodically read the last 'n' rows of a simple table?"
- Next in thread: Hamelech Al Hakol: "Re: SQL question: How to periodically read the last 'n' rows of a simple table?"
- Reply: Hamelech Al Hakol: "Re: SQL question: How to periodically read the last 'n' rows of a simple table?"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 3 Feb 2005 00:39:27 -0600
There is nothing built in (thankfully, in my opinion)
> In this case, the data column's timestamp value is not the time of insert
> but rather a timestamp generated by a 3rd party application. There may be
> a significant gap between this timestamp and the time at insert.
I would just add a row_create_date with a type of datetime to your table,
with a default of getdate (assuming all of your current insert statements
name the columns that are being inserted into:
INSERT tablename (column1, column2, etc)
VALUES (...
OR
SELECT column1
And you will have your solution. Consider using GMT dates if you have to
deal with this sort of thing 24 hours a day, as daylight saving time can be
a pain once a year!)
-- ---------------------------------------------------------------------------- Louis Davidson - drsql@hotmail.com SQL Server MVP Compass Technology Management - www.compass.net Pro SQL Server 2000 Database Design - http://www.apress.com/book/bookDisplay.html?bID=266 Note: Please reply to the newsgroups only unless you are interested in consulting services. All other replies may be ignored :) "Hamelech Al Hakol" <djmarcusIGNORE@m5incIGNORE.com> wrote in message news:uwo5YEWCFHA.4052@TK2MSFTNGP15.phx.gbl... > Hi > > I am painfully aware of the 'set' nature of the rows (order not defined), > however I was hoping that there was a vendor-specific way (as there is in > Oracle and I hear in SQL/Server 2005) to refer to a row number (in > acknowledgement that new data is generally appended to the file). Infact, > this is precisely how the app reads the data when its under Oracle - by > row number. > > The table in question actually does have a temporal-based column and I am > able to retrieve rows according to a time range. My application does read > the rows using a rolling time range (to keep up with the data). > > The issue is really a conceptual one: How to detect newly added data that > falls in an interval that has already been processed by the app? > > Once the app reads a range of time values it naturally moves the rolling > window (time range) to the next interval. So any data inserted in an > interval that has already been processed by the app is never detected !! > That is a glaring hole. > > In this case, the data column's timestamp value is not the time of insert > but rather a timestamp generated by a 3rd party application. There may be > a significant gap between this timestamp and the time at insert. > > Obviously given the ability to read a range of records based on row id, > makes the problem go away. > > -Thanks for the thought > David > > > > Anith Sen wrote: >> There is no such thing as the last 'n' rows in a table, since tables are >> logical representations of sets of entities. Sets by themselves has no >> inherent order and the tuples in a set are identified by the identifying >> attributes, not by positional numbers. >> >> >>>>The table does not have a column with a uniquely increasing value. The >>>>database is read-only as far as my app is concenred, meaning I can't add >>>>a column, an index or otherwise make any changes to the table. >> >> >> Unless you have a column which can determine the order in which the rows >> are inserted into the table, you cannot do this. Generally, in many such >> circumstances, the table designer might opt to include a column with >> temporal datatype ( in t-SQL, one might use DATETIME or SMALLDATETIME >> column ) that keeps track of the time of insertion. This would help in >> retrieving a specific subset that can be considered "last". >>
- Next message: oj: "Re: Backup database without stored procedures"
- Previous message: Gary K: "HOST_NAME length"
- In reply to: Hamelech Al Hakol: "Re: SQL question: How to periodically read the last 'n' rows of a simple table?"
- Next in thread: Hamelech Al Hakol: "Re: SQL question: How to periodically read the last 'n' rows of a simple table?"
- Reply: Hamelech Al Hakol: "Re: SQL question: How to periodically read the last 'n' rows of a simple table?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|