我正在执行此代码以在我的数据库中创建用户。
CREATE LOGIN john WITH PASSWORD = 'john123';
GO
USE mytestdb;
GO
CREATE USER [john] FOR LOGIN [john]
GO
ALTER USER [john] WITH DEFAULT_SCHEMA=[dbo]
GO
ALTER ROLE [db_datareader] ADD MEMBER [john]
GO
ALTER ROLE [db_datawriter] ADD MEMBER [john]
GO
GRANT EXECUTE ON SCHEMA::[dbo] TO [john]
GO
但我想删除这个我创建的用户。
我尝试发出此命令
USE myDB;
DROP USER john;
GO
但它会抛出此错误。
数据库主体在数据库中拥有一个模式,不能删除。
答案 0 :(得分:1)
您可以在那里看到模式所有者:
SELECT s.name AS [schema_name], dp1.name AS [owner_name]
FROM sys.schemas AS s
INNER JOIN sys.database_principals AS dp1 ON dp1.principal_id = s.principal_id
然后改变所有者:
ALTER AUTHORIZATION ON SCHEMA::[xxxx] TO [dbo]
“xxxx” - 所有者为'john'的架构名称