SQL Server 2008 在 CLR 存储过程中接收用户定义的表类型?

发布于 2024-10-09 09:31:08 字数 340 浏览 4 评论 0原文

我在 SQL Server 2008 中有表值参数,例如:

CREATE TYPE UserType AS TABLE
(
    UserID int,
    UserName nvarchar(100),
    UserPassword nvarchar(100)
)

我可以在 SQL CLR 存储过程中以某种方式使用此类型吗?例如作为输入参数?

[SqlProcedure]
public static void SomeFunction (/* what type should be here ?? */)
{
     //
}

I have table-valued parameters in SQL Server 2008, e.g.:

CREATE TYPE UserType AS TABLE
(
    UserID int,
    UserName nvarchar(100),
    UserPassword nvarchar(100)
)

Can I use this type somehow in my SQL CLR stored procedure? For example as input parameter?

[SqlProcedure]
public static void SomeFunction (/* what type should be here ?? */)
{
     //
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

奶气 2024-10-16 09:31:08

我不相信你可以。 映射 CLR 参数数据页面表示没有(SQL Server CLR或 .NET Framework)表数据类型的等效项。


或者,引用@Jani 的链接

用户定义的表类型不能作为表值参数传递给在 SQL Server 进程中执行的托管存储过程或函数,也不能从该存储过程或函数返回

I don't believe you can. The page Mapping CLR Parameter Data indicates that there are no (SQL Server CLR or .NET Framework) equivalents for the table data type.


Or, to quote from @Jani's link:

A user-defined table type cannot be passed as a table-valued parameter to, or be returned from, a managed stored procedure or function executing in the SQL Server process

若相惜即相离 2024-10-16 09:31:08

Transact-SQL 表值函数将调用函数的结果具体化到中间表中。由于它们使用中间表,因此可以支持对结果的约束和唯一索引。当返回大量结果时,这些功能非常有用。

相比之下,CLR 表值函数代表了流式处理的替代方案。不要求将整组结果具体化在单个表中。托管函数返回的IEnumerable对象由调用表值函数的查询的执行计划直接调用,并以增量方式消耗结果。这种流模型确保在第一行可用后可以立即使用结果,而不是等待整个表被填充。如果返回大量行,这也是一个更好的选择,因为它们不必作为一个整体在内存中具体化。例如,托管表值函数可用于解析文本文件并将每一行作为一行返回。

参考

Transact-SQL table-valued functions materialize the results of calling the function into an intermediate table. Since they use an intermediate table, they can support constraints and unique indexes over the results. These features can be extremely useful when large results are returned.

In contrast, CLR table-valued functions represent a streaming alternative. There is no requirement that the entire set of results be materialized in a single table. The IEnumerable object returned by the managed function is directly called by the execution plan of the query that calls the table-valued function, and the results are consumed in an incremental manner. This streaming model ensures that results can be consumed immediately after the first row is available, instead of waiting for the entire table to be populated. It is also a better alternative if you have very large numbers of rows returned, because they do not have to be materialized in memory as a whole. For example, a managed table-valued function could be used to parse a text file and return each line as a row.

Reference

追我者格杀勿论 2024-10-16 09:31:08

尝试使用类而不是表值参数:

public class UserType
{
    int UserID { get; set; }
    string UserName { get; set; }
    string UserPassword { get; set; }
)

[SqlProcedure]
public static void SomeFunction (UserType type)
{
     //
}

Try use class instead of table-valued parameter:

public class UserType
{
    int UserID { get; set; }
    string UserName { get; set; }
    string UserPassword { get; set; }
)

[SqlProcedure]
public static void SomeFunction (UserType type)
{
     //
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文