是否可以在另一个用户定义的 table 类型中使用用户定义的 table 类型 sql

Is it possible to use user defined table type inside another user defined table type in sql

是否可以在 SQL 中的另一个用户定义 table 类型中使用用户定义的 table 类型(嵌套的用户定义 table 类型)。

CREATE TYPE A AS TABLE
(
    A_Id int
)

GO


CREATE TYPE B AS TABLE
(
    B_Id int,
    A_Id A --Need To Use A as data type in B
)
GO

我有前辈要发送 table 行的数据 table。

Table
1.Item1
   1.Vendor1
   2.Vendor2
2.Item1
   1.Vendor1
   2.Vendor2

请帮助如何将 table 行内的 table 数据从 asp.net 发送到 sql。通过循环或者是否有任何简单的方法将嵌套的 table 数据发送到服务器。

没有。为什么会这样?这不是 SQL 服务器(或任何关系数据库)的工作方式。

来自TechNet's page on User-Defined Table Types

Restrictions

User-defined table types have the following restrictions:

  • A user-defined table type cannot be used as a column in a table or a field in a structured user-defined type.

"Nesting"在关系数据库中是通过使用Foreign keys

实现的

您甚至不能在两个用户定义的 table 类型之间创建外键约束。

你可以做的是创建两个 table 类型,其中一个有一个列来保留另一个的 ID,如下所示:

CREATE TYPE A AS TABLE
(
    A_Id int
)

GO


CREATE TYPE B AS TABLE
(
    B_Id int,
    A_Id int -- "FK"
)
GO