将数据从 ODBC 源合并到 SQL Server 数据库的最有效方法
我需要不断地将数据从 ODBC 数据源合并(更新插入/删除)到 SQL Server 2008 数据库(行数从一行到 100000 行不等)
您会推荐什么作为最有效的方法(使用 .net 3.5 ) :
- 使用
SqlBulkCopy
到临时表中,然后使用临时表作为源通过Merge命令调用存储过程。 - 调用具有表值参数的存储过程,其中数据作为参数发送 (
SqlDbType.Structured
),表参数用作合并命令的源。 通过表参数发送的数据是否批量发送到服务器?在存在 > 的情况下是否可以有效地使用它? 1000 行? - 使用合并命令调用存储过程,该命令使用 OpenRowset 批量从 ODBC 源获取数据(使用链接服务器?)
- 任何其他方式。
谢谢你!
I need to constantly merge (upsert/delete) data from an ODBC data source to a SQL Server 2008 database (number of rows vary from one row to 100000 of rows)
What would you recommend as the most efficient approach (using .net 3.5 ):
- Use
SqlBulkCopy
into temp table then call stored procedure with Merge command using temp table as source. - Calling a Stored procedure that has a table value parameter, where data is sent as a parameter (
SqlDbType.Structured
), table parameter used as source of merge command.
Is the data sent via table parameter sent to server in a bulk operation? Is it possible and efficient to use it in cases where there are > 1000 rows? - Call stored procedure with merge command that uses
OpenRowset
bulk to get the data from the ODBC source (use linked server?) - Any other way.
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这取决于导入的触发器是什么。如果要每 10 分钟安排一次,我会使用选项 1 或创建一个 SSIS 包来执行与选项 1 相同的操作。JNK 是正确的,最好使用永久表,它将避免分配如果需要的话,它可以让你从中间开始处理这个过程。
在 SSIS 中,您的工作流程如下所示:
创建包后,您可以通过 SQL 代理对其进行调度。确保在包属性上设置 DontSaveSensitiveData 选项来创建包,这样就不会出现奇怪的加密错误。
This kind of depends on what the trigger is for the import. If it's going to be scheduled every 10 minutes or something I would use either option 1 or create an SSIS package that will do the same thing as option 1. JNK is correct that it would be better to use a permanent table, it will avoid allocated issues and it will allow you to pick up the process from the middle if needed.
In SSIS your workflow would look like this:
Once the package is created you can schedule it through the SQL Agent. Make sure to create the package with the DontSaveSensitiveData option set on the package properties so you don't get strange encryption errors.