是否可以在 sql 中的另一个用户定义的表类型中使用用户定义的表类型 [英] Is it possible to use user defined table type inside another user defined table type in sql

查看:25
本文介绍了是否可以在 sql 中的另一个用户定义的表类型中使用用户定义的表类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Is it possible to use user defined table type inside another user defined table type in SQL (nested user define table types).

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

我有前辈用一个表发送行的数据表.

I have senior to send the data table of rows with in a table.

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

请帮助如何将表行中的表数据从asp.net 发送到 sql.通过循环或者有什么简单的方法可以将嵌套表数据发送到服务器.

Please help how to send the table data within table rows from asp.net to sql. through looping or is there any simple way to send the nested table data to server.

推荐答案

没有.为什么会这样?这不是 SQL Server(或任何关系数据库,就此而言)的工作方式.

No. Why would it be? That's not how SQL Server (or any relational database, for that matter) work.

来自 TechNet 关于用户定义表类型的页面:

限制

用户定义的表类型有以下限制:

User-defined table types have the following restrictions:

  • 用户定义的表类型不能用作表中的列或结构化用户定义类型中的字段.

关系数据库中的嵌套"是通过使用外键来实现的

"Nesting" in relational databases are achieved by using Foreign keys

您甚至无法在两个用户定义的表类型之间创建外键约束.

You can't even create a foreign key constraint between two user defined table types.

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

What you can do is create two table types that one of them have a column to keep the id of the other, like this:

CREATE TYPE A AS TABLE
(
    A_Id int
)

GO


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

这篇关于是否可以在 sql 中的另一个用户定义的表类型中使用用户定义的表类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆