使用 XML 进行多次插入与 INSERT...VALUES...SELECT...UNION ALL
对于 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你尝试过吗?老实说,对于 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 requireUNION ALL
, and there is also a new approach called table-valued parameters.