SQL Server: Script to make Database Read Only and Read Write

In this post, I am sharing script to make a database read-only or changing from read-only to read-write mode of SQL Server.

When we are attaching MDF or LDF files, sometimes the database status shows that the database is in Read-Only mode.

If we have some historical archive databases, we can also set Read-Only mode to that database so that any database user can only read the database.

Script to make database Read-Only:

Script to make database Read-Write:

If you get any error like that database is already in use, you can alter database for a single user which close all existing connections.

You can use this script to make database only for single user.

Anvesh Patel

Leave a Reply

2 Comments on "SQL Server: Script to make Database Read Only and Read Write"

Notify of
avatar
Sort by:   newest | oldest | most voted
Raghuveer Yadav
Guest

I request you to post on failover Cluster.
I m facing problem for last 15 days.

wpDiscuz