Make database readonly

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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s