How to detect a SQL Server database's read-only status using T-SQL?

后端 未结 4 1037
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-01 09:36

I need to know how to interrogate a Microsoft SQL Server, to see if a given database has been set to Read-Only or not.

Is that possible, using T-SQL?

4条回答
  •  囚心锁ツ
    2021-01-01 10:21

    Querying sys.databases for checking a DB's Read-Only property will only give the right information if the database has been explicitly set to Read-Only mode.

    For databases that are in the passive servers (e.g. in AlwaysOn technology Secondary Servers), even though the databases cannot be written into, their Read-Only mode in sys.databases would still be set as False(0).

    Hence, it is advisable to check the Read-Only mode of databases using the statement:

    SELECT DATABASEPROPERTYEX('MyDBNAme', 'Updateability');
    

提交回复
热议问题