MSSQL 更新查询将结果显示到网格
我有一个 SQL 查询,它根据与另一个表中的记录的联接来更新一个表中的 ID。问题是,由于某种原因,我不明白更新查询实际上是将查询结果显示到 SSMS 中的网格。这导致我的机器上出现“内存不足异常”,因为它试图在网格中显示超过 100 万个结果。这很有趣,因为查询不应该显示除更新的记录数之外的任何内容。有什么想法我做错了吗?
这是我的查询的示例:
UPDATE MyDatabase.dbo.Notes
SET ParentID = A.ID
FROM MyDatabase.dbo.Notes N
JOIN MyDatabase.dbo.Actions A ON N.OldID = A.OldID
WHERE A.OldID IS NOT NULL
AND N.OldID IS NOT NULL
AND N.ParentID IS NULL
I have an SQL Query that updates IDs in one table based on a join to records in another table. The issue is that for some reason that I do not understand the Update query is actually displaying the results on the query to the grid in SSMS. This is causing an 'Out of Memory Exception' on my machine because it is trying to show 1 million + results in the grid. It is interesting because the query should not display anything except the number of records updated. Any ideas what I am doing wrong?
Here is an example of my query:
UPDATE MyDatabase.dbo.Notes
SET ParentID = A.ID
FROM MyDatabase.dbo.Notes N
JOIN MyDatabase.dbo.Actions A ON N.OldID = A.OldID
WHERE A.OldID IS NOT NULL
AND N.OldID IS NOT NULL
AND N.ParentID IS NULL
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您问题中列出的代码本身不会导致 SSMS 中的网格产生任何输出
The code listed in your question will not cause any output to the Grid in SSMS by itself
显然有一个更新触发器,其中有一个 select 语句。我禁用了触发器,查询立即运行。
Apparently there is an update trigger with a select statement in it. I disabled the trigger and the query ran instantly.