Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I list user defined types in a SQL Server database?

I need to enumerate all the user defined types created in a SQL Server database with CREATE TYPE, and/or find out whether they have already been defined.

With tables or stored procedures I'd do something like this:

if exists (select * from dbo.sysobjects where name='foobar' and xtype='U')     drop table foobar 

However I can't find the equivalent (or a suitable alternative) for user defined types! I definitely can't see them anywhere in sysobjects.

Can anyone enlighten me?

like image 482
jammycakes Avatar asked Sep 10 '08 15:09

jammycakes


People also ask

What are user-defined data types in SQL Server?

User-defined data types are based on the system data types in Microsoft SQL Server. User-defined data types can be used when several tables must store the same type of data in a column and you must ensure that these columns have exactly the same data type, length, and NULLability.


1 Answers

Types and UDTs don't appear in sys.objects. You should be able to get what you're looking for with the following:

select * from sys.types where is_user_defined = 1 
like image 102
jwolly2 Avatar answered Sep 24 '22 18:09

jwolly2