SQL Server 2008 在 CLR 存储过程中接收用户定义的表类型?
我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不相信你可以。 映射 CLR 参数数据页面表示没有(SQL Server CLR或 .NET Framework)表数据类型的等效项。
或者,引用@Jani 的链接:
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:
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
尝试使用类而不是表值参数:
Try use class instead of table-valued parameter: