4

我想知道是否可以在SQL Server 2008成員中創建一個CLR用戶定義類型,其成員將是表變量。創建一個具有SQL @tables作爲其成員的UDT

你知道,你可以聲明表變量:

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

所以我看中了UDT與幾個成員,每個成員的是(當然不同的表)表定義的方式,因此它倒是有可能說:

select id from @typed_var.table1 where ... 

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

我有一種感覺,我想就這一個太多,BU t似乎無法在互聯網上找到確定的「是」或「否」。
有沒有可能?

+0

我認爲這個問題是有關:http://stackoverflow.com/questions/4626292/how-to-use-table-variable-in -a-dynamic-sql-statement – 2011-07-09 01:14:56

+0

而這篇文章有一些非常有用的東西:http://www.sommarskog.se/dynamic_sql.html#FirstEncounter – 2011-07-09 01:20:22

回答

1

不,這是不可能的。 SQL服務器不會讓你SELECT或INSERT到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. 
相關問題