是否“设置交易级别”?需要开始交易吗?
在 MS SQL Server 中,如果我在存储过程中使用“SET TRANSACTION ISOLATION LEVEL”,是否需要将 select 语句包装在 BEGIN/END TRANSACTION 块中?以下内容会按预期工作吗?
CREATE PROCEDURE my_sproc AS
BEGIN
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
SELECT * FROM MyTable
END
In MS SQL Server, if I use "SET TRANSACTION ISOLATION LEVEL" in a stored procedure, do I need to wrap the select statements in a BEGIN/END TRANSACTION Block? Will the following work as expected?
CREATE PROCEDURE my_sproc AS
BEGIN
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
SELECT * FROM MyTable
END
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
TRANSACTION ISOLATION LEVEL
设置是连接级别设置。无需将其包装在事务中。话虽这么说,您知道在此设置中您会出现脏读等情况吗?
您可以通过使用锁定提示在逐个查询的基础上完成相同的操作,例如:
SELECT * FROM MyTable WITH (NOLOCK)
The
TRANSACTION ISOLATION LEVEL
setting is a connection-level setting. There's no need to wrap it in a transaction.That being said, you understand you will have dirty reads and such from this setting?
You can accomplish the same thing on a query-by-query basis by using locking hints such as:
SELECT * FROM MyTable WITH (NOLOCK)
SET TRANSACTION ISOLATION LEVEL 与 BEGIN/COMMIT/ROLLBACK 不同
没有直接链接或交互:不同的概念
SET TRANSACTION ISOLATION LEVEL is different to BEGIN/COMMIT/ROLLBACK
There is no direct link or interaction: different concepts