Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Column information of a user defined Table Type

Tags:

sql

sql-server

I need to get all information for user defined table type columns (name ,type , null or not ) so I can generate a backup scrip for all table types I got .

like image 529
Lanaa Avatar asked Dec 07 '22 19:12

Lanaa


1 Answers

I have just written and tested this on SQL Server 2014, hopefully should work with all versions.

Select t.name   [TableTypeName]
      ,SCHEMA_NAME(t.schema_id)  [SchemaName]
      ,c.name   [Column Name]
      ,y.name   [Data Type]
      ,c.max_length
      ,c.precision
      ,c.is_identity
      ,c.is_nullable
From sys.table_types t
Inner join sys.columns c on c.object_id = t.type_table_object_id
Inner join sys.types y ON y.system_type_id = c.system_type_id
WHERE t.is_user_defined = 1
  AND t.is_table_type = 1
like image 62
M.Ali Avatar answered Dec 10 '22 13:12

M.Ali