隔离级别 - 可序列化.我应该什么时候使用它? [英] Isolation Level - Serializable. When should I use this?

查看:28
本文介绍了隔离级别 - 可序列化.我应该什么时候使用它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道 Serializable 的隔离级别是所有隔离级别中限制性最强的.我很好奇什么样的应用程序需要这种级别的隔离,或者我什么时候应该考虑使用它?

I understand that an Isolation level of Serializable is the most restrictive of all isolation levels. I'm curious though what sort of applications would require this level of isolation, or when I should consider using it?

推荐答案

问自己以下问题:如果有人在您的事务运行时将新行插入到您的数据中,会不会很糟糕?这会以不可接受的方式干扰您的结果吗?如果是这样,请使用 SERIALIZABLE 级别.

Ask yourself the following question: Would it be bad if someone were to INSERT a new row into your data while your transaction is running? Would this interfere with your results in an unacceptable way? If so, use the SERIALIZABLE level.

来自 MSDN 关于 SET TRANSACTION ISOLATION LEVEL:

可序列化

对数据集设置范围锁,阻止其他用户更新或将行插入数据集中直到交易完成.这是最严格的四个隔离级别.因为并发性较低,使用此选项只有在必要时.这个选项有与设置 HOLDLOCK 相同的效果所有 SELECT 语句中的所有表一笔交易.

Places a range lock on the data set, preventing other users from updating or inserting rows into the data set until the transaction is complete. This is the most restrictive of the four isolation levels. Because concurrency is lower, use this option only when necessary. This option has the same effect as setting HOLDLOCK on all tables in all SELECT statements in a transaction.

因此,您的事务在其整个生命周期内维护所有锁——即使是那些通常在使用后丢弃的锁.这使得所有事务似乎一次运行一个,因此名称为 SERIALIZABLE.维基百科关于隔离级别的说明:

So your transaction maintains all locks throughout its lifetime-- even those normally discarded after use. This makes it appear that all transactions are running one at a time, hence the name SERIALIZABLE. Note from Wikipedia regarding isolation levels:

可序列化

此隔离级别指定所有交易都发生在一个完全孤立的时尚;即,好像所有系统中的交易有串行执行,在其他.DBMS 可以执行两个或同时进行更多交易只有当串行的错觉可以维持执行.

This isolation level specifies that all transactions occur in a completely isolated fashion; i.e., as if all transactions in the system had executed serially, one after the other. The DBMS may execute two or more transactions at the same time only if the illusion of serial execution can be maintained.

这篇关于隔离级别 - 可序列化.我应该什么时候使用它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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