patternsqlModerate
What permission is needed to set Database read-only?
Viewed 0 times
neededwhatreadpermissiondatabaseonlyset
Problem
I am dbowner of a database which I want to set read-only. (through sql management studio). When I try that I get a permission error (297)
Which role is needed to perform that action?
Which role is needed to perform that action?
Solution
Form Query Analyzer or Management Studio, you can issue the following command:
As mentioned here, you need the alter database rights and you must set the database to single mode.
Changing the state of a database or filegroup to READ_ONLY or
READ_WRITE requires exclusive access to the database.
ALTER DATABASE database-name SET READ_ONLYAs mentioned here, you need the alter database rights and you must set the database to single mode.
Changing the state of a database or filegroup to READ_ONLY or
READ_WRITE requires exclusive access to the database.
USE master;
GO
ALTER DATABASE AdventureWorks2012
SET SINGLE_USER
WITH ROLLBACK IMMEDIATE;
GO
ALTER DATABASE AdventureWorks2012
SET READ_ONLY;
GO
ALTER DATABASE AdventureWorks2012
SET MULTI_USER;
GOCode Snippets
ALTER DATABASE database-name SET READ_ONLYUSE master;
GO
ALTER DATABASE AdventureWorks2012
SET SINGLE_USER
WITH ROLLBACK IMMEDIATE;
GO
ALTER DATABASE AdventureWorks2012
SET READ_ONLY;
GO
ALTER DATABASE AdventureWorks2012
SET MULTI_USER;
GOContext
StackExchange Database Administrators Q#18360, answer score: 11
Revisions (0)
No revisions yet.