SQL Server - Database Read - Only

After attaching sample database - AdventureWorks2012,I noticed the database in Read-Only state as shown in below image :







To change your database to Read-Write state ,execute below code:

ALTER DATABASE [AdventureWorks2012] SET READ_WRITE




To change your database to Read-Only state ,execute below code: 

ALTER DATABASE [AdventureWorks2012] SET READ_ONLY 

 

You can also Set Database Read - Only state to TRUE/FALSE through SSMS 2012 ,Under Object Explorer, right-click on your  Database  - >  Properties - > State - >  Database Read - Only - > True/False  as shown in below image :





If your database is in  Read - Only state , you cannot make any changes to your database :

USE [AdventureWorks2012]

ALTER DATABASE [AdventureWorks2012] SET READ_ONLY WITH NO_WAIT

CREATE TABLE TEST (col1 int)

Msg 3906, Level 16, State 1, Line 5
Failed to update database "AdventureWorks2012" because the database is read-only.






No comments: