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
This will list all table types and their columns:
select tt.name, c.name from sys.table_types tt
inner join sys.columns c on c.object_id = tt.type_table_object_id
order by c.column_id
You can add a where clause and select other columns, as appropriate, to get what you need.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With