如何删除具有db owner权限的SQL Server用户

时间:2021-11-15 12:47:54

I need to drop a user with dbowner schema from a SQL Server database. I cannot drop it as it is since I get this error message

我需要从SQL Server数据库中删除具有dbowner模式的用户。因为我收到此错误消息,所以我无法删除它

Drop failed for User 'network service'. (Microsoft.SqlServer.Smo)

用户'网络服务'丢弃失败。 (Microsoft.SqlServer.Smo)

The database principal owns a schema in the database, and cannot be dropped. (Microsoft SQL Server, Error: 15138)

数据库主体在数据库中拥有一个模式,不能删除。 (Microsoft SQL Server,错误:15138)

When I try to uncheck the schema owned by this user to remove db owner it does nothing. My question is how I can drop this user or edit its name from 'network service' to 'NT AUTHORITY\NETWORK SERVICE'

当我尝试取消选中此用户拥有的架构以删除db owner时,它什么都不做。我的问题是如何删除此用户或将其名称从“网络服务”编辑为“NT AUTHORITY \ NETWORK SERVICE”

2 个解决方案

#1


7  

take a look at this:

看看这个:

http://www.itorian.com/2012/12/the-database-principal-owns-schema-in.html

It suggests that you need to add another owner first

它表明您需要先添加另一个所有者

#2


4  

I had the same problem, i run two script then my problem is solved.

我有同样的问题,我运行两个脚本然后我的问题解决了。

try this:

In this query you can get user schema as a result for AdventureWorks database

在此查询中,您可以获取AdventureWorks数据库的用户架构

USE AdventureWorks;
SELECT s.name
FROM sys.schemas s
WHERE s.principal_id = USER_ID('your username');

after take schema name you can alter authorization on schema like this:

在获取模式名称后,您可以更改模式的授权,如下所示:

ALTER AUTHORIZATION ON SCHEMA::db_owner TO dbo;

in this query db_owner schema name that get from first query.

在此查询中,从第一个查询获取的db_owner模式名称。

finally you can delete user without error.

最后你可以删除用户而不会出错。

my source: SQL SERVER – Fix: Error: 15138

我的来源:SQL SERVER - 修复:错误:15138

#1


7  

take a look at this:

看看这个:

http://www.itorian.com/2012/12/the-database-principal-owns-schema-in.html

It suggests that you need to add another owner first

它表明您需要先添加另一个所有者

#2


4  

I had the same problem, i run two script then my problem is solved.

我有同样的问题,我运行两个脚本然后我的问题解决了。

try this:

In this query you can get user schema as a result for AdventureWorks database

在此查询中,您可以获取AdventureWorks数据库的用户架构

USE AdventureWorks;
SELECT s.name
FROM sys.schemas s
WHERE s.principal_id = USER_ID('your username');

after take schema name you can alter authorization on schema like this:

在获取模式名称后,您可以更改模式的授权,如下所示:

ALTER AUTHORIZATION ON SCHEMA::db_owner TO dbo;

in this query db_owner schema name that get from first query.

在此查询中,从第一个查询获取的db_owner模式名称。

finally you can delete user without error.

最后你可以删除用户而不会出错。

my source: SQL SERVER – Fix: Error: 15138

我的来源:SQL SERVER - 修复:错误:15138