Make database readonly

Posted by Joe Enos on April 25, 2021 · 1 min read

Pretty straightforward to set a database to readonly mode. If the database is currently in use, it may get complicated, but as long as it's currently unused, this should work:

-- Set to readonly:
use master;
go
alter database mydatabase set read_only with no_wait;
go

-- Re-enable writing:
use master;
go
alter database mydatabase set read_write with no_wait;
go