SQL CLR - 检索数据/更新结果
作为业务逻辑的一部分,我必须从 SQL 表中检索 2000 多行。通过一些复杂的、程序性的、业务逻辑来运行这些行(是的,它必须是程序性的,并且我迄今为止研究的所有运行求和技术都不会降低效率)。然后我必须更新数据库并返回结果。
使用 SQLDataReader - 数据从 SQL 中流出,并进入我的逻辑 - 效果很好。
逻辑迭代数据,并进行必要的更改。
现在保存更改 - 我真的不想通过将参数填充到 UPDATE 语句来发送结果。如果我在 SQL 中获得结果,我会将临时表与基表连接起来,并在单个 TSQL Update 语句中执行所有更新。我的“表”位于 SQL CLR 中,而基表位于 SQL 端。
我已经阅读了有关将结果序列化为 XML 并使用 varchar 变量将其全部传输的技术 - 但我使用的是 SQL Server 2008 R2。
我研究过 UDT 和表值参数 - 但您不能使用它们在 SQL CLR 和 SQL 之间传输数据。
如果 SQL CLR 应该与复杂的业务逻辑一起使用 - 是否有发送数据的最佳实践方法?我还没有找到直接解决或讨论这个问题的例子。
As part of my business logic I have to retrieve 2000+ rows from a sql table. Run those rows through some complex, procedural, business logic (yes it has to be procedural, and all running sum techiques I research so far don't cut it for efficiency). Then I have to update the database, and return the results.
Using SQLDataReader - the data is streamed out of SQL, and into my logic - which works just fine.
The logic iterates over the data, and makes the necessary changes.
Now to save the changes - I really don't want to sent the result over by filling parameters to an UPDATE statement. If I had the results over in SQL, I would join the temp table with the base table, and perform all the updates in a single TSQL Update statement. By my "table" is in SQL CLR, and the base table is over on the SQL side.
I've read the techniques about serializing out the results to XML, and transfer it all over with in a varchar variable - but I'm using SQL Server 2008 R2.
I've looked at UDT, and Table Value Parameters - but you can't use those to transfer data between SQL CLR and SQL.
If SQL CLR is suppose to be used with complex business logic - isn't there a best practise means of sending the data over? I have not found an example yet that directly addresses or talks to this issue.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了一次性更新所有列,在对数据库的一次调用中的各种记录中,您可以使用 XML。
下面是您可以使用的查询示例。
您可以使用任何您想要的连接操作进行更新、插入、删除,此代码适用于从 SQL Server 2005 到 Denali。
In order to update all your columns at once, in various records in a single call to the database you are right to use XML.
Below a sample of the query you could use.
you can do Updates, inserts, delete, with any join operation you want, this code will work from SQL server 2005 to denali.