为什么从自连接临时 table 更新真实 table 不起作用,但在使用真实 table 时却有效?

why does updating a real table from a self-join temp table is not working but when using a real table it works?

场景如下:

程序 1 创建临时文件 table #t.

程序1执行程序2。

程序 2 填充#t。

在步骤 1 中,我从 #t 插入到一个真实的 table 中,以便我可以查看数据。 数据在那里。

查看此数据后,我立即使用自连接进行更新。像这样:

  update b
  set b.column1 = a.column3
  from #t a
    inner join #t b on a.id = b.id;

应该更新的记录未更新。

但是,如果我将 #t 更改为真实的 table "dbo.t" 并执行完全相同的操作,它就会起作用。

我很困惑。任何人都知道为什么会这样?谢谢

根据 MS SQL 文档:

A local temporary table created in a stored procedure is dropped automatically when the stored procedure is finished. The table can be referenced by any nested stored procedures executed by the stored procedure that created the table. The table cannot be referenced by the process that called the stored procedure that created the table.

https://docs.microsoft.com/en-us/sql/t-sql/statements/create-table-transact-sql?view=sql-server-2017