简体   繁体   English

是否可以使用 SqlBulkCopy 将信息插入到超过 2 个表的视图中?

[英]It is possible to use SqlBulkCopy to insert information into a view over 2 tables?

I am moving to use SqlBulkCopy to deal with large insertions into some databases.我打算使用 SqlBulkCopy 来处理对某些数据库的大量插入。 This has lead to great performance improvements for one db.这为一个 db 带来了巨大的性能改进。

However, another targeted db table is a view composing 2 tables.但是,另一个目标数据库表是由 2 个表组成的视图。 Applying the single table code leads to "System.Data.SqlClient.SqlException: View or function 'dbo.vwParameter' is not updatable because the modification affects multiple base tables".应用单表代码会导致“System.Data.SqlClient.SqlException: View or function 'dbo.vwParameter' 不可更新,因为修改会影响多个基表”。 It is possible to flatten the view into one table without causing many complications, though undesired because it saves a good bit disk space.可以将视图展平到一个表中而不会引起很多复杂性,尽管这是不受欢迎的,因为它节省了大量的磁盘空间。

So is it possible to use SqlBulkCopy in this context, and I am just doing something wrong?那么是否可以在这种情况下使用 SqlBulkCopy ,而我只是做错了什么? Or if not, what might be a good work-around that preserves the view for reading?或者如果没有,什么可能是一个很好的解决方法来保留阅读视图?

It turned out that SqlBulkCopy ignored my instead of triggers by default.事实证明,SqlBulkCopy 默认忽略了我的而不是触发器。 All I had to do was pass SqlBulkCopyOptions.FireTriggers to the SqlBulkCopy constructor.我所要做的就是将 SqlBulkCopyOptions.FireTriggers 传递给 SqlBulkCopy 构造函数。

Have you reviewed the documentation about updating data in views?您是否查看过有关在视图中更新数据的文档 There are two possible solutions described there, and the first one is probably the one you want.那里描述了两种可能的解决方案,第一个可能是您想要的。

You can use view with SqlBulkCopy.您可以将视图与 SqlBulkCopy 一起使用。
But I believe your problem is that the view that you have is not updatable.但我相信你的问题是你的观点是不可更新的。
There are certain requirements that view has to meet to be updatable.视图必须满足某些要求才能更新。
You can find more info here http://msdn.microsoft.com/en-us/library/ms187956.aspx你可以在这里找到更多信息http://msdn.microsoft.com/en-us/library/ms187956.aspx
Look for 'Updatable Views' section.查找“可更新视图”部分。

I would suggest you to populate each of those two tables directly, one at a time, if possible?我建议您直接填充这两个表中的每一个,一次一个,如果可能的话?

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

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