将数据从 ODBC 源合并到 SQL Server 数据库的最有效方法

发布于 2024-09-29 06:56:03 字数 427 浏览 0 评论 0原文

我需要不断地将数据从 ODBC 数据源合并(更新插入/删除)到 SQL Server 2008 数据库(行数从一行到 100000 行不等)

您会推荐什么作为最有效的方法(使用 .net 3.5 ) :

  1. 使用SqlBulkCopy到临时表中,然后使用临时表作为源通过Merge命令调用存储过程。
  2. 调用具有表值参数的存储过程,其中数据作为参数发送 (SqlDbType.Structured),表参数用作合并命令的源。 通过表参数发送的数据是否批量发送到服务器?在存在 > 的情况下是否可以有效地使用它? 1000 行?
  3. 使用合并命令调用存储过程,该命令使用 OpenRowset 批量从 ODBC 源获取数据(使用链接服务器?)
  4. 任何其他方式。

谢谢你!

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 ):

  1. Use SqlBulkCopy into temp table then call stored procedure with Merge command using temp table as source.
  2. 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?
  3. Call stored procedure with merge command that uses OpenRowset bulk to get the data from the ODBC source (use linked server?)
  4. Any other way.

Thank you!

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

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

发布评论

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

评论(1

戴着白色围巾的女孩 2024-10-06 06:56:03

这取决于导入的触发器是什么。如果要每 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:

  • truncate staging table
  • create data flow task to import data from source to staging table, handle errors if needed
  • call stored procedure to merge data

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.

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