Answers:
这应该为您提供所需的东西:
;with objects_cte as
(
select
o.name,
o.type_desc,
case
when o.principal_id is null then s.principal_id
else o.principal_id
end as principal_id
from sys.objects o
inner join sys.schemas s
on o.schema_id = s.schema_id
where o.is_ms_shipped = 0
and o.type in ('U', 'FN', 'FS', 'FT', 'IF', 'P', 'PC', 'TA', 'TF', 'TR', 'V')
)
select
cte.name,
cte.type_desc,
dp.name
from objects_cte cte
inner join sys.database_principals dp
on cte.principal_id = dp.principal_id
where dp.name = 'YourUser';
这将获得您的特定用户拥有的对象('YourUser'
当然是替代品)。该查询提取的对象类型为:
要显示所有非sa数据库所有者:
SELECT suser_sname( owner_sid ) OwnerID , * FROM sys.databases where suser_sname( owner_sid ) <> 'sa'
如果您需要SQL系统作业所有者:
select s.name,l.name
from msdb..sysjobs s
left join master.sys.syslogins l on s.owner_sid = l.sid
where l.name is not null and l.name <> 'sa'
order by l.name