Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Permissions required to run 'ALTER DATABASE SET SINGLE_USER' statement on SQL Server 2008

I've came across the case when the following statement throws an error saying it can't be executed because of the permission:

ALTER DATABASE [{0}] SET SINGLE_USER WITH ROLLBACK IMMEDIATE

Couldn't find anywhere on the web any information about the permissions it needs.

like image 819
Oleg Sakharov Avatar asked Mar 21 '12 05:03

Oleg Sakharov


People also ask

How do I give permission to run a database in SQL Server 2008?

Use SQL Server Management StudioExpand Stored Procedures, right-click the procedure to grant permissions on, and then select Properties. From Stored Procedure Properties, select the Permissions page. To grant permissions to a user, database role, or application role, select Search.

What is Alter permission in SQL Server?

When granted on a scope, ALTER also bestows the ability to alter, create, or drop any securable that is contained within that scope. For example, ALTER permission on a schema includes the ability to create, alter, and drop objects from the schema.

How do I grant permissions to SQL database?

Using SQL Server Management StudioRight-click a stored procedure and select Properties. In the Stored Procedure Properties -stored_procedure_name dialog box, under select a page, select Permissions. Use this page to add users or roles to the stored procedure and specify the permissions those users or roles have.


2 Answers

ALTER DATABASE:

Requires ALTER permission on the database.

Some specific SET permissions are listed in ALTER DATABASE SET options:

  • EMERGENCY: ALTER DATABASE permission for the subject database is required to change a database to the offline or emergency state. The server level ALTER ANY DATABASE permission is required to move a database from offline to online.
  • DB_CHAINING: To set this option, requires CONTROL SERVER permission on the database.
  • TRUSTWORTHY: To set this option, requires CONTROL SERVER permission on the database.
like image 185
Remus Rusanu Avatar answered Nov 15 '22 07:11

Remus Rusanu


Try this from admin account:

USE [YOUR_DB]
GO
GRANT ALTER TO your_user
GO

But mind that the login must have a user in the specified DB.

Or, if you want to grant this permission on every database on the server, then you can grant the permission on the server level to the login:

USE master
GO
GRANT ALTER ANY DATABASE TO your_login
GO
like image 40
Andrey Gurinov Avatar answered Nov 15 '22 09:11

Andrey Gurinov