'Get column information for a User-Defined Table Type
How can I get back the column information for a User-Defined Table Type?
EXEC sp_columns TABLENAME
gets me back all the column information for a table.
I want to do the same thing for a User-Defined Table Type called SearchList and roughly the same column information back.
I want to get this so I can code generate the Data Tables that I need in c#.
UPDATE TO SHOW WHAT I USED
select c.name as COLUMN_NAME, t.name as [TYPE_NAME], c.precision as [PRECISION], c.is_nullable as [NULLABLE], c.system_type_id, c.precision as [LENGTH]
from sys.columns c, sys.types t
where c.object_id = (select type_table_object_id from sys.table_types where name = 'SearchList')
and t.user_type_id = c.user_type_id
order by c.column_id
Solution 1:[1]
I have used below query in my project to get the table type with column name and data type.
select tt.name AS table_Type, c.name AS table_Type_col_name,st.name AS
table_Type_col_datatype
from sys.table_types tt
inner join sys.columns c on c.object_id = tt.type_table_object_id
INNER JOIN sys.systypes AS ST ON ST.xtype = c.system_type_id
order by tt.name
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Mridul Srivastava |
