Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"ALTER ROLE db_owner ADD MEMBER A" doesn't work

When I execute ALTER ROLE db_owner ADD MEMBER A it gives out following error.

Msg 15151, Level 16, State 1, Line 4
Cannot alter the role 'A', because it does not exist or you do not have permission.

Here ALTER ROLE it mentions that;

Limitations and restrictions

You cannot change the name of a fixed database role.

But I can't find any relationship to this with the error. What I'm trying to do is adding a member not changing the fixed role name.

Any support in resolving this matter is highly appreciated

like image 276
Anuruddha Avatar asked Mar 03 '17 04:03

Anuruddha


1 Answers

I think that you are missing a step. You have a login, but you are not adding the login as a user to the database. All the steps below are what you need. The CREATE USER step (a database level call) seems to be missing from your work.

I don't think you need the CREATE LOGIN, I just wanted to include that so one could see all it takes to do this.

USE [master]
GO
CREATE LOGIN [A] WITH PASSWORD=N'<password>', DEFAULT_DATABASE=[master], CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF
GO
USE [YourDatabase]
GO
CREATE USER [A] FOR LOGIN [A]
GO 
ALTER ROLE db_owner ADD MEMBER [A]
GO

Change YourDatabase to the proper value before you try this.

like image 165
R. Richards Avatar answered Nov 10 '22 03:11

R. Richards