我应该使用SQL事务,而读记录? [英] Should I be using SQL transactions, while reading records?

查看:71
本文介绍了我应该使用SQL事务,而读记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SQL事务用于插入,更新,但是否应该用于读取记录?

SQL transactions is used for insert, update, but should it be used for reading records?

推荐答案

如果您要查询在一个查询中的所有记录,和他们拉回来一气呵成,没有必要。一切都在一个隐式事务包裹起来。也就是说,即使你退一万条记录,即使其他进程正在改变的记录,你会看到什么都一百万条记录看起来像在同一个时间点。

If you are querying all the records in a single query, and pulling them back in one go, there is no need. Everything is wrapped up in an implicit transaction. That is to say, even if you get back one million records, and even if other processes are changing the records, you'll see what all one million records looked like at the same point in time.

您确实需要一个交易(和,常,具体的锁定提示)唯一次在只读工艺有:结果
- 您阅读记录零碎并且需要闲来无事,而你itterate虽然改变的值。 [如在ADO连接的记录,你再通过光标]结果
- 您看了一些资料,做了一些计算,然后读了一些相关的数据,但假设没有在平均时间改变。

The only times you would really need a transaction (and, often, a specific locking hint) in a read only process are:
- You read the records "piece-meal" and need nothing else to alter the values while you itterate though. [Such as a connected recordset in ADO that you then cursor through.]
- You read some data, do some calculations, then read some related data, but on the assumption nothing changed in the mean time.

结果

在总之,你需要的交易,当你想其他进程必须从停止干扰SQL语句之间的数据。

In short, you need transactions when you want other processes to be stopped from interfering with your data between SQL statements.

这篇关于我应该使用SQL事务,而读记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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