I am working with SQL Server 2008 R2
and SQL Server 2016
.
I have bunch of User-Defined Data Types
but they dont show in sys.all_objects
. What is the true catalog view which can return all user-defined objects?
Thanks
Types are not objects that would show up in the objects table. You can use the types table:
select *
from sys.types
WHERE is_user_defined = 1
or you can use this bigger query from the MS docs to return all your objects, types, and schema collections:
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