SQL Server – Change Database State

--Make Database Read Only

 

USE​​ [master]

GO

ALTER​​ DATABASE​​ [TESTDB]​​ SET​​ READ_ONLY​​ WITH​​ NO_WAIT

GO

 

--Make Database Read/Write

 

USE​​ [master]

GO

ALTER​​ DATABASE​​ [TESTDB]​​ SET​​ READ_WRITE​​ WITH​​ NO_WAIT

GO

 

 

 

--If you face error that if database is already in use, you can resolve the same by making database in single user mode

 

--1. Set the database to single mode:

ALTER​​ DATABASE​​ [TESTDB]​​ SET​​ SINGLE_USER​​ WITH​​ ROLLBACK​​ IMMEDIATE;

 

 

 

--2. Set the database to Multi-user mode

ALTER​​ DATABASE​​ [TESTDB]

SET​​ MULTI_USER​​ WITH​​ ROLLBACK​​ IMMEDIATE

 

Knowledge worth sharing...Share on linkedin
Linkedin
Share on facebook
Facebook
Share on google
Google
Share on twitter
Twitter
Bookmark the permalink.

Leave a Reply

Leave a Reply

Your email address will not be published. Required fields are marked *