用于排除所有数据库的所有孤立用户的脚本,仅列出活动用户 [英] Script to Exclude all orphan users for all databases and list only active users
问题描述
我需要一个需要列出所有活动数据库的脚本应排除所有孤儿用户和其他非活动用户的用户。
I need a script which needs to list all the active database users which should exclude all the orphan users and other inactive users .
提前致谢
推荐答案
https://www.mssqltips.com/sqlservertip/3439/script-to-drop-all-orphaned-sql-server -database-users /
https://www.mssqltips.com/sqlservertip/3439/script-to-drop-all-orphaned-sql-server-database-users/
从sys.database_principals中选择DB_NAME()[database],名称为[user_name],type_desc,default_schema_name,create_date,modify_date
其中键入('G','S','U')
和authentication_type<> 2 - 仅当您在SQL Server 2012和主要版本上运行时才使用此过滤器你有"包含数据库"
和[sid] in(从sys.server_principals中选择[sid],其中键入('G','S','U'))
和name in('dbo','guest','INFORMATION_SCHEMA','sys','MS_DataCollectorInternalUser')
select DB_NAME() [database], name as [user_name], type_desc,default_schema_name,create_date,modify_date from sys.database_principals
where type in ('G','S','U')
and authentication_type<>2 -- Use this filter only if you are running on SQL Server 2012 and major versions and you have "contained databases"
and [sid] in ( select [sid] from sys.server_principals where type in ('G','S','U') )
and name in ('dbo','guest','INFORMATION_SCHEMA','sys','MS_DataCollectorInternalUser')
这篇关于用于排除所有数据库的所有孤立用户的脚本,仅列出活动用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!