真正的sys.all_objects是什么?

时间:2018-10-31 16:08:44

标签: sql-server system-views

我正在与SQL Server 2008 R2SQL Server 2016合作。

我有一堆User-Defined Data Types,但它们没有显示在sys.all_objects中。可以返回所有用户定义对象的真实目录视图是什么?

谢谢

1 个答案:

答案 0 :(得分:2)

类型不是将显示在对象表中的对象。您可以使用类型表:

select * 
from sys.types
WHERE is_user_defined = 1

或者您可以使用MS docs中更大的查询来返回所有对象,类型和模式集合:

SELECT 'OBJECT' AS entity_type  
    ,USER_NAME(OBJECTPROPERTY(object_id, 'OwnerId')) AS owner_name  
    ,name   
FROM sys.objects 
UNION   
SELECT 'TYPE' AS entity_type  
    ,USER_NAME(TYPEPROPERTY(SCHEMA_NAME(schema_id) + '.' + name, 'OwnerId')) AS owner_name  
    ,name   
FROM sys.types   
UNION  
SELECT 'XML SCHEMA COLLECTION' AS entity_type   
    ,COALESCE(USER_NAME(xsc.principal_id),USER_NAME(s.principal_id)) AS owner_name  
    ,xsc.name   
FROM sys.xml_schema_collections AS xsc JOIN sys.schemas AS s  
    ON s.schema_id = xsc.schema_id  

GO