简体   繁体   English

在SQLCLR中的SqlBulkCopy存储过程?

[英]SqlBulkCopy in SQLCLR stored procedure?

I created SQLCLR stored procedure that retrieve large amount of data from external service. 我创建了从外部服务检索大量数据的SQLCLR存储过程。 Can I bulk copy the data to a new table in the same SQLCLR stored procedure? 是否可以将数据批量复制到同一SQLCLR存储过程中的新表中?

I'll zoom out here to the general problem of how to expose data from a service inside SQL. 在这里,我将讨论如何在SQL内部公开数据的一般问题。 What can might do is rewrite your stored procedure as a Table Valued CLR function that streams the results. 可以做的是将您的存储过程重写为一个表值CLR函数 ,该函数可以流式传输结果。 Then you can use like this: 然后,您可以像这样使用:

insert into MyTable(id, name)
select id, name from dbo.MyTableFunc(agrs) 

The infrastructure for this is well optimized, I used it and was quickly able to get it to some 3k rows per second when I stopped optimizing, and the bottleneck was in getting the rows over the network. 对此的基础结构进行了很好的优化,我使用了它,并且当我停止优化时,很快就能够将其每秒提高到约3k行,而瓶颈在于通过网络获取行。

The upside of exposing the service as a function is that you also directly use it in queries and joins, no need to store it in to a table on disk first (extra step with slow disks, transaction log, locks yadayada). 将服务公开为功能的好处是,您还可以直接在查询和联接中使用它,而无需先将其存储到磁盘上的表中(慢速磁盘,事务日志,锁定yadayada的额外步骤)。 It also cancels gracefully and you can do top 100 etc. 它也会优雅地取消,您可以top 100

If you tell us more/ give some code we can help more. 如果您告诉我们更多/提供一些代码,我们可以提供更多帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM