简体   繁体   English

“ ALTER ROLE db_owner ADD MEMBER A”不起作用

[英]“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. 当我执行ALTER ROLE db_owner ADD MEMBER A它发出以下错误。

Msg 15151, Level 16, State 1, Line 4 讯息15151,第16级,州1,第4行
Cannot alter the role 'A', because it does not exist or you do not have permission. 无法更改角色“ A”,因为该角色不存在或您没有权限。

Here ALTER ROLE it mentions that; 在这里ALTER ROLE提到了这一点;

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 非常感谢您对解决此问题的支持

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. 您的工作似乎缺少CREATE USER步骤(数据库级别的调用)。

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. 我认为您不需要CREATE LOGIN ,我只是想包含它,这样一来,人们可以看到完成此操作所需的一切。

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. 在尝试此之前,请将YourDatabase更改为适当的值。

First you drop existing user role then use below command: 首先,您删除现有的用户角色,然后使用以下命令:

USE Databasename
GO
-- create new role for your s to belong to
CREATE ROLE s
GO
-- add s Role to db_owner
EXEC sys.sp_addrolemember 
    @rolename = N'db_owner',
    @membername = N's';
GO
GO

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM