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

Giuseppe picture Giuseppe · May 28, 2010 · Viewed 46.5k times · Source

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?

Answer

p.campbell picture p.campbell · May 28, 2010

The information is stored in sys.databases.

SELECT name, is_read_only 
FROM sys.databases 
WHERE name = 'MyDBNAme'
GO

--returns 1 in is_read_only when database is set to read-only mode.