Skip to content
Advertisement

How to select from User Defined Table Type?

Select * from sys.table_types where user_type_id = TYPE_ID(N'dbo.udt_test');

The above query returns me data but when I try to query the data within, it says dbo.udt_test not exists?

Select * from dbo.udt_test

https://msdn.microsoft.com/en-us/library/ms131086.aspx

Referred to the above link, there should be no problem with the select query to display data. May I know if I missing something obvious here?

Advertisement

Answer

Because dbo.udt_test is a Table Type, not a Table instance.

The link in your question shows how a User Defined Type is defined and is used as data type for column.

you seem to have created a new table type.

You can create table variable of type dbo.udt_test and use that table to insert/update/delete/select data from it.

In the link, you have this code..

INSERT INTO dbo.Points (PointValue) VALUES (CONVERT(Point, '3,4'));

‘Point’ is a type here. You cannot do select Point from Sometable same as in the case of Select VARCHAR from Sometable

In the same way, you cannot have SELECT * FROM TABLETYPE

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement