MSSQL更新查询将结果显示到网格

时间:2021-11-16 11:20:19

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?

我有一个SQL查询,它根据连接更新一个表中的ID到另一个表中的记录。问题是由于某些原因我不明白Update查询实际上是在查询中将结果显示在SSMS中的网格上。这导致我的机器出现“内存不足”,因为它试图在网格中显示100万个+结果。这很有趣,因为除了更新的记录数之外,查询不应显示任何内容。我有什么想法我做错了吗?

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

2 个解决方案

#1


1  

The code listed in your question will not cause any output to the Grid in SSMS by itself

您的问题中列出的代码本身不会导致SSMS中的网格输出

  • Double check that what you pasted is actually your exact query
    • Sometimes extra code can be hiding below the fold
    • 有时额外的代码可以隐藏在折叠之下

  • 仔细检查您粘贴的内容实际上是您的确切查询有时额外的代码可以隐藏在首屏下方

  • Check for triggers on any tables involved
  • 检查所涉及的任何表的触发器

#2


1  

Apparently there is an update trigger with a select statement in it. I disabled the trigger and the query ran instantly.

显然有一个更新触发器,其中包含一个select语句。我禁用了触发器,查询立即运行。

#1


1  

The code listed in your question will not cause any output to the Grid in SSMS by itself

您的问题中列出的代码本身不会导致SSMS中的网格输出

  • Double check that what you pasted is actually your exact query
    • Sometimes extra code can be hiding below the fold
    • 有时额外的代码可以隐藏在折叠之下

  • 仔细检查您粘贴的内容实际上是您的确切查询有时额外的代码可以隐藏在首屏下方

  • Check for triggers on any tables involved
  • 检查所涉及的任何表的触发器

#2


1  

Apparently there is an update trigger with a select statement in it. I disabled the trigger and the query ran instantly.

显然有一个更新触发器,其中包含一个select语句。我禁用了触发器,查询立即运行。