使用 XML 进行多次插入与 INSERT...VALUES...SELECT...UNION ALL

发布于 2025-01-07 13:31:51 字数 366 浏览 4 评论 0原文

对于 SQL Server 2005,如果我想插入大约 20 或 30 行,每行三列,哪种方法更快、更高效?调用应用程序是 C# 4.0 .Net 控制台应用程序。

a) 将值作为 XML 传递到存储过程并解析它并执行插入

b) 按照此处的建议使用 INSERT...VALUES... SELECT() UNION ALL 构造 SQL 命令:SQL Server 2005:使用单个查询插入多行 ?

谢谢。

For SQL Server 2005, if I want to insert about 20 or 30 rows each with three columns, which approach is faster and efficient? The calling application is a C# 4.0 .Net console application.

a) Passing the values as XML to a stored proc and parsing it and doing the insert
OR
b) Construct a SQL command with INSERT...VALUES... SELECT() UNION ALL as suggested here: SQL Server 2005: Insert multiple rows with single query ?

Thank you.

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

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

发布评论

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

评论(1

浮生未歇 2025-01-14 13:31:51

你尝试过吗?老实说,对于 20 或 30 行,您真的很难找到差异。在更大的范围内,我预计 XML 提取数据所涉及的额外数据和解析的成本将使其成为效率较低的选择。在 SQL Server 2008 中,有一个更高效的 VALUES() 构造函数,不需要 UNION ALL,并且还有一种称为表值参数的新方法。

Did you try them? To be honest, for 20 or 30 rows, you'd be really hard pressed to find a difference. At a larger scale, I would expect the cost of extra data and parsing involved with XML to extract data would make it the less efficient choice. In SQL Server 2008 there is a more efficient VALUES() constructor that doesn't require UNION ALL, and there is also a new approach called table-valued parameters.

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