如何记住上次阅读的记录 [英] How to remember last record read

查看:100
本文介绍了如何记住上次阅读的记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述







你能看看这个问题是否有解决办法?

我有一个数据库,我必须从中读取每条记录并处理

该记录。新记录一直在增加,所以我需要返回

并查看新记录并处理它们。


但是:


- 数据库设计中没有''identity''列(所以我不能

跟踪使用数字变量读取的最后一条记录)


- 我不允许更新数据库(因此我无法标记我读过的

记录)。


我的问题是:我怎么知道我已经阅读过的记录和

哪些我还没读过?我不想两次处理记录

并且不想错过任何记录。


这个问题有一个已知的解决方案吗?有什么想法吗?


谢谢。

解决方案



使用具有日期时间类型的字段。每次记录是

插入更新此最新日期时间。查看记录时,请获取此字段的最新信息,并通过再次从表中获取最新日期时间来检查是否与

记录不同

Madhivanan


2005年3月2日22:36:48 -0800, fr ******* @ hotmail.com 写道:


(剪辑)

我的问题是:我怎么知道我已经阅读过哪些记录以及哪些记录还没有读过?我不想两次处理记录
并且不想错过任何记录。




你好弗朗西斯,


Madhivanan已经指出了使用日期时间列

的可能性以及在表中插入行的日期。如果这样的专栏不是
可用且你不允许添加一个,这里有一些其他的

选项。


*你说你不允许更新数据库。这张桌子只是

吗?如果是这样,您可以创建一个新表来保存已经处理过的所有行的ey值




*如果不允许要将表添加到数据库中,您可以考虑在另一个

数据库中跟踪已经处理过的行。不过,这非常黑客。很难保持

数据库同步,特别是如果你必须恢复到

备份。


*另一种选择是在桌面上使用触发器。要么在那个触发器中完成处理(如果它很短也不会失败),

或用插入行的主键写行到另一个

表,您可以使用它来决定要处理哪些行。请注意,即使这个触发器也会稍微减慢插入过程!


Best,Hugo

-


(删除_NO_和_SPAM_以获取我的电子邮件地址)


(fr ******* @ hotmail.com)写道:

你们可以看看是否有这个问题的解决方案吗?

我有一个数据库,我必须从中读取每个记录和过程
那条记录。新的记录一直在增加,所以我需要回来检查新的记录并加工它们。

但是:

- 有数据库设计中没有''identity''列(因此我无法通过使用数字变量跟踪最后读取的记录)

- 我不允许更新数据库(所以我不能标记我读过的
记录)。

我的问题是:我怎么知道我已经阅读过的记录和哪些记录?读了吗?我不想两次处理记录
并且不想错过任何记录。

这个问题有一个已知的解决方案吗?任何想法?




那么你的流程在哪里生活?它是存储过程还是客户端

程序?如果它的存储过程可能会有临时表。


有关此过程和情况的更多信息将需要

才能给出一个好的答案。

-

Erland Sommarskog,SQL Server MVP, es **** @ sommarskog.se


SQL Server SP3联机丛书
http://www.microsoft.com/sql/techinf...2000/books.asp




Hi,

Can you guys see if there''s a solution to this problem?

I have a database from which I have to read each record and process
that record. New records are being added all the time, so I need to go
back and check for new records and process them.

However:

-- there is no ''identity'' column in the database design (so I cannot
keep track of the last record read by use of a numeric variable)

-- I am not allowed to update the database (so I cannot flag the
records I have read).

My problem is: how can I know which records I have already read and
which ones I haven''t read yet? I don''t want to process records twice
and don''t want to miss any records.

Is there a known solution to this problem? Any ideas?

Thanks.

解决方案


Use a filed which has the datetime of type. Every time a record is
inserted update this with latest datetime. When viewing the record get
the latest of this field and check whether this different from the
record by getting the latest datetime from the table again

Madhivanan


On 2 Mar 2005 22:36:48 -0800, fr*******@hotmail.com wrote:

(snip)

My problem is: how can I know which records I have already read and
which ones I haven''t read yet? I don''t want to process records twice
and don''t want to miss any records.



Hi francisds,

Madhivanan already pointed out the possibility to use a datetime column
with the date a row is inserted in the table. If such a column is not
available and you''re not allowed to add one, here are a few other
options.

* You say that you''re not allowed to update the database. Is that just
this table? If so, you can create a new table to hold the ey values of
all rows you already have processed.

* If you''re not allowed to add tables to the database either, you could
consider keeping track of rows already processed in a table in another
database. This is quite a hack, though. It can be hard to keep the
databases synchronized, especially if you ever have to restore to a
backup.

* Yet another option would be to use a trigger on the table. Either do
the complete processing in that trigger (if it''s short and can''t fail),
or write rows with the primary keys of the inserted rows to another
table that you can use to decide which rows to process. Note that even
this trigger will slow down the insert process somewhat!

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)


(fr*******@hotmail.com) writes:

Can you guys see if there''s a solution to this problem?

I have a database from which I have to read each record and process
that record. New records are being added all the time, so I need to go
back and check for new records and process them.

However:

-- there is no ''identity'' column in the database design (so I cannot
keep track of the last record read by use of a numeric variable)

-- I am not allowed to update the database (so I cannot flag the
records I have read).

My problem is: how can I know which records I have already read and
which ones I haven''t read yet? I don''t want to process records twice
and don''t want to miss any records.

Is there a known solution to this problem? Any ideas?



So where does your process live? Is it a stored procedure or a client
program? If it''s stored procedure maybe a temp table would do.

More information about this process and the circumstances would be
needed to give a good answer.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp


这篇关于如何记住上次阅读的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆