How to select all columns for a custom type

I have created some custom types that will be used as table parameters. Is there a way to select columns, how can I select columns for a table:

SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME LIKE 'MyTable' 

Edit: yes, I tried to read MSDN, but I do not see the information there. My current workaround is to create a persistent table as follows:

 CREATE TABLE Placeholder(copy-and-paste all the columns from my type here) 

I can then select from INFORMATION_SCHEMA.COLUMNS and remove the Placeholder when done.

+4
source share
2 answers

This will give you a list of columns for the table type TVPTest

 select c.* from sys.table_types as tt inner join sys.columns as c on tt.type_table_object_id = c.object_id where tt.name = 'TVPTest' 
+9
source

The accepted answer works well, but I expanded it a bit to get more details:

 select c.name ,ColumnType = t.name ,ColumnLength = c.max_length from sys.table_types as tt join sys.columns as c on tt.type_table_object_id = c.object_id join sys.types t on t.system_type_id = c.system_type_id and t.user_type_id = c.user_type_id -- and tt.type_table_object_id = c.object_id where tt.name = 'StatusDetail' 
+1
source

All Articles