0

I have a database table with a Y/N flag in one column. I want to read all records where the flag is 'N' and after processing a record, set the flag to 'Y' in that record. Is it correct, and reasonable, to do this at the same time, using two separate connections? Or should I read the entire table first and update only after I'm done with the reading? What's the correct approach to this?

The database involved is Netezza, in case it matters.

4

2 回答 2

1

主要取决于您的设计和需求。

国旗有多重要?如果在处理它们之前设置所有标志时出现问题怎么办......等等。

为什么你需要两个连接我不理解,通常你有一个保持打开的连接。我不知道 Netezza 的块,但也可以使某些系统同时进行选择和更新。

你可以这样做:

  1. 加载一堆,处理它们,然后更新所有标志。(最快,一次失败=全部失败)
  2. 加载一堆,处理一个,更新一个标志,下一步处理..(非常快,一个失败不要全部击中)
  3. 一一获取并更新它们。(将是最慢但最安全的)
于 2012-02-23T18:41:06.767 回答
1

你应该先阅读然后更新。不是异步的。如果“选择”部分需要很长时间,您应该考虑分批进行。您可以使用单独的连接,但应该确信您已完成阅读。

于 2012-02-23T18:42:23.540 回答