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

后端 未结 4 1060
佛祖请我去吃肉
佛祖请我去吃肉 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:02

    I was trying to use the p.campbell's answer to check if my Azure SQL DB is the primary one or the read only replica - it didn't work. Both the primary DB and the replica returned had 0 on the is_read_only field.

    Here's what worked for me:

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

    the above select statement returns string 'READ_ONLY' or 'READ_WRITE'.

提交回复
热议问题