我们可以从函数返回临时表而不是表变量吗?

发布于 2024-09-28 15:10:46 字数 68 浏览 12 评论 0原文

我有一个函数...其中我将返回类型作为表变量... 但是如果我们使用临时表,性能将会提高......因为我们有更多的数据。

I have a function...in which I have return type as table variable...
But performance will be increased if we use temp tables..as we have more data.

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

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

发布评论

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

评论(4

笛声青案梦长安 2024-10-05 15:10:46

不,您不能“返回”临时表 - 您可以在调用函数之前创建该临时表,并让您的函数将数据写入该临时表。

但这往往会变得相当混乱……您需要确保在调用该函数之前创建了临时表……

您是否真的、诚实地测量了该函数的性能两种方法??我不认为临时表总是更快......使用表变量的方法对我来说似乎更干净、更直观。

No, you cannot "return" a temp table - you can create that temp table before calling your function, and have your function write data into that temp table.

But this has a tendency to get rather messy .... you need to make sure to have the temp table created before calling the function.....

Have you really, honestly measured the performance of the two approaches?? I don't think temp tables are just always faster.... the approach with the table variable seems a lot cleaner and more intuitive to me.

自我难过 2024-10-05 15:10:46

您当然不能返回临时表。但您可以在调用存储过程中定义它。请记住,这适用于存储过程。您无法从函数内部访问临时表。

You cannot of course return the temp table. But you can define it in the calling stored procedure. Bear in mind this will only work for stored procedures. You cannot access temporary tables from within functions.

我不会写诗 2024-10-05 15:10:46

您可以使用返回实际表的 CLR 表值函数。 CLR 函数是您可以用母语 C#、VB 等编写的函数,并且 dll 嵌入在数据库中。

从这里了解更多信息:

http://msdn.microsoft.com/en-我们/library/ms131103.aspx

You can use CLR Table Valued functions that returns the actual table. CLR functions are functions you can write in your native language C#, VB etc. and the dll are embedded in the database.

Learn more about it from here:

http://msdn.microsoft.com/en-us/library/ms131103.aspx

聽兲甴掵 2024-10-05 15:10:46

这涵盖了几乎所有方式的优点/缺点和示例代码:

如何在存储过程之间共享数据,作者:Erland Sommarskog< /a>

Using OUTPUT Parameters
Table-valued Functions
    Inline Functions
    Multi-statement Functions
Using a Table
    Sharing a Temp Table
    Process-keyed Table
    Global Temp Tables
INSERT-EXEC
Table Parameters and Table Types
Using the CLR
OPENQUERY
Using XML
Using Cursor Variables

this cover just about every way with pros/cons and sample code:

How to Share Data Between Stored Procedures by Erland Sommarskog

Using OUTPUT Parameters
Table-valued Functions
    Inline Functions
    Multi-statement Functions
Using a Table
    Sharing a Temp Table
    Process-keyed Table
    Global Temp Tables
INSERT-EXEC
Table Parameters and Table Types
Using the CLR
OPENQUERY
Using XML
Using Cursor Variables
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文