创建一个UDT,其成员是SQL @tables。

4
我想知道在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 (...)

我觉得我对这个问题要求过高,但在互联网上似乎找不到明确的答案。
这种情况有可能吗?


我认为这个问题是相关的:https://dev59.com/9m445IYBdhLWcg3w7ug0 - ypercubeᵀᴹ
这篇文章有一些非常有用的东西:http://www.sommarskog.se/dynamic_sql.html#FirstEncounter - ypercubeᵀᴹ
1个回答

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.

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接