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.

Please share your ideas and opinions about this topic with me, your contribution will add true value to this topic.
If anyone has doubts on this topic then please do let me know by leaving comments or send me an email.

If you like this post, then please share it with others.
Please follow dbrnd.com, I will share my experience towards the success of Database Research and Development Activity.

I put up a post every day, please keep reading and learning.
Discover Yourself, Happy Blogging !
Anvesh M. Patel.

More from dbrnd.com

Leave a Reply

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

Notify of

Sort by:   newest | oldest | most voted
Raghuveer Yadav
Raghuveer Yadav
7 months 11 days ago

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