Technical Article

Show all User-Defined Datatypes for all Databases

,

This procedure displays all user-defined datatypes in all databases on a server.  Another example of the power of dynamic T-SQL, this procedure dynamically generates SELECT statements for the systypes tables in each database and UNIONs them together so that they display in one recordset.

USE MASTER
GO

CREATE PROCEDURE sp_ShowAllUserTypes

AS

DECLARE @sql nvarchar(4000)

SELECT @sql = ISNULL(@sql + char(13) + 'UNION' + 
CHAR(13), '') +
'SELECT ''' + name + ''' as db, *
FROM ' + name + '.dbo.systypes
WHERE xusertype > 256'
/*User-defined types always have an xusertype greater than 256*/FROM master.dbo.sysdatabases

--PRINT @sql /*Uncomment for debugging*/EXEC sp_executesql @sql

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating