简体   繁体   中英

SqlBulkCopy in SQLCLR stored procedure?

I created SQLCLR stored procedure that retrieve large amount of data from external service. Can I bulk copy the data to a new table in the same SQLCLR stored procedure?

I'll zoom out here to the general problem of how to expose data from a service inside SQL. What can might do is rewrite your stored procedure as a Table Valued CLR function that streams the results. 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.

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). It also cancels gracefully and you can do top 100 etc.

If you tell us more/ give some code we can help more.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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