删除 SQL Server 数据库中的角色?

发布于 2024-08-17 06:20:01 字数 253 浏览 5 评论 0原文

我正在尝试删除 SQL Server 数据库中的角色之一。我删除了该角色中的所有成员,当我尝试删除角色时,我收到此错误消息:

Msg 15138, Level 16, State 1, Line 13
The database principal owns a schema in the database, and cannot be dropped.

有人知道为什么吗?我检查了拥有的架构,它只有自己的名称中的复选标记。

I am trying to drop one of the role in my SQL Server database. I dropped all the members from the role and when i tried to drop role i got this error message:

Msg 15138, Level 16, State 1, Line 13
The database principal owns a schema in the database, and cannot be dropped.

Does anyone know why? I checked the Owned Schema and it only had check sign in its own name.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

风透绣罗衣 2024-08-24 06:20:01

15138 错误是由于您尝试删除的用户拥有架构所致。

如果运行以下查询,您将获得用户拥有的架构。

USE DatabaseName; 
SELECT s.name
FROM sys.schemas s
WHERE s.principal_id = USER_ID('UserName');

假设它返回“db_denydatareader”模式。然后你可以分配
使用以下查询将该架构设置为默认用户“dbo”。

ALTER AUTHORIZATION ON SCHEMA::db_denydatareader TO dbo;

15138 error is due to the user you are trying to delete owns a schema.

If you run the below query you will get the schema owned by the user.

USE DatabaseName; 
SELECT s.name
FROM sys.schemas s
WHERE s.principal_id = USER_ID('UserName');

Let us say it returns 'db_denydatareader' schema. Then you can assign
that schema to default user 'dbo' using the below query.

ALTER AUTHORIZATION ON SCHEMA::db_denydatareader TO dbo;
无风消散 2024-08-24 06:20:01

您无法删除拥有架构的数据库主体。您必须将架构所有权转移给其他数据库主体或删除该架构,然后才能删除数据库主体。

You cannot drop a database principal that owns a schema. You have to transfer the schema ownership to some other database principal or drop the schema before you can drop the database principal.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文