我如何知道我的数据库是否处于可序列化模式?

时间:2016-12-18 20:05:43

标签: sql sql-server sql-server-2008 tsql sql-server-2012

据我所知,您可以查看dmv sys.databases以获取隔离信息:

 select name
        , s.snapshot_isolation_state
        , snapshot_isolation_state_desc
        , is_read_committed_snapshot_on
        , recovery_model
        , recovery_model_desc
        , collation_name
    from sys.databases s
    ORDER BY 1 

我不了解如何使用sys.databases中的信息来确定隔离模式。 您如何知道当前为数据库设置了什么类型的隔离模式?

2 个答案:

答案 0 :(得分:2)

DBCC UserOptions(检查"隔离级别")

  

返回当前连接的SET选项active(set)。

https://msdn.microsoft.com/en-us/library/ms180065.aspx

DBCC UserOptions 
+-------------------------+----------------+
| Set Option              | Value          |
+-------------------------+----------------+
| textsize                | 2147483647     |
+-------------------------+----------------+
| language                | us_english     |
+-------------------------+----------------+
| dateformat              | mdy            |
+-------------------------+----------------+
| datefirst               | 7              |
+-------------------------+----------------+
| lock_timeout            | -1             |
+-------------------------+----------------+
| quoted_identifier       | SET            |
+-------------------------+----------------+
| arithabort              | SET            |
+-------------------------+----------------+
| ansi_null_dflt_on       | SET            |
+-------------------------+----------------+
| ansi_warnings           | SET            |
+-------------------------+----------------+
| ansi_padding            | SET            |
+-------------------------+----------------+
| ansi_nulls              | SET            |
+-------------------------+----------------+
| concat_null_yields_null | SET            |
+-------------------------+----------------+
| isolation level         | read committed |
+-------------------------+----------------+
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
DBCC UserOptions  
+-------------------------+--------------+
| Set Option              | Value        |
+-------------------------+--------------+
| textsize                | 2147483647   |
+-------------------------+--------------+
| language                | us_english   |
+-------------------------+--------------+
| dateformat              | mdy          |
+-------------------------+--------------+
| datefirst               | 7            |
+-------------------------+--------------+
| lock_timeout            | -1           |
+-------------------------+--------------+
| quoted_identifier       | SET          |
+-------------------------+--------------+
| arithabort              | SET          |
+-------------------------+--------------+
| ansi_null_dflt_on       | SET          |
+-------------------------+--------------+
| ansi_warnings           | SET          |
+-------------------------+--------------+
| ansi_padding            | SET          |
+-------------------------+--------------+
| ansi_nulls              | SET          |
+-------------------------+--------------+
| concat_null_yields_null | SET          |
+-------------------------+--------------+
| isolation level         | serializable |
+-------------------------+--------------+

答案 1 :(得分:1)

SQL Server中的数据库没有默认的隔离级别。您在sys.databases中看到的是数据库是否允许快照隔离以及read committed是否是乐观的(即使用快照来强制执行read committed)或悲观。如果没有任何应用程序设置不同,则无论数据库如何,都会读取默认隔离级别。