Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select all the columns for a user-defined type

I have created some user-defined types to be used as table-valued parameters. Is there any way I could select their columns, just like I can select columns for a table:

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

Edit: yes, I tried to read MSDN, but I don't see the information there. My current workaround is to create a permanent table as follows:

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

Then I can select from INFORMATION_SCHEMA.COLUMNS and drop Placeholder when I am done.

like image 581
Arne Lund Avatar asked Jun 07 '11 16:06

Arne Lund


People also ask

How do I get columns from a table type in SQL?

You can get the MySQL table columns data type with the help of “information_schema. columns”. SELECT DATA_TYPE from INFORMATION_SCHEMA. COLUMNS where table_schema = 'yourDatabaseName' and table_name = 'yourTableName'.

How do I select multiple columns in select query?

To select multiple columns from a table, simply separate the column names with commas! For example, this query selects two columns, name and birthdate , from the people table: SELECT name, birthdate FROM people; Sometimes, you may want to select all columns from a table.


1 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'
like image 162
Mikael Eriksson Avatar answered Oct 03 '22 15:10

Mikael Eriksson