创建一个以SQL @tables为成员的UDT

时间:2010-09-27 20:09:32

标签: sql sql-server-2008 table-valued-parameters user-defined-types

我想知道是否有可能在SQL Server 2008成员中创建一个CLR用户定义类型,其成员是表变量。

你知道,你可以声明一个表变量:

declare @foo table (row_id int not null ... );

所以我想要一个有几个成员的UDT,每个成员都是一个以这种方式定义的表(当然是一个不同的表),所以可以说:

select id from @typed_var.table1 where ...

insert into @typed_var.table3(id) values (...)

我确实有一种感觉,我想要这个,但似乎无法在互联网上找到明确的是或否。
它有可能吗?

1 个答案:

答案 0 :(得分:1)

不,这是不可能的。 SQL Server不允许您选择或插入UDT的属性。

我试过这个,并得到以下错误:

create type childTable as table
(
    a int,
    b int
)

create type childTable2 as table
(
    c int
)

create type parentTable as table
(
    firstChild childTable,
    secondChild childTable2
)

Msg 350, Level 16, State 1, Line 1
The column "firstChild" does not have a valid data type. A column cannot be of a user-defined table type.