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:
ALTER DATABASE [DatabaseName] SET READ_ONLY WITH NO_WAIT
Script to make database Read-Write:
ALTER DATABASE [DatabaseName] SET READ_WRITE WITH NO_WAIT
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.
ALTER DATABASE [DatabaseName] SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
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.