gpt4 book ai didi

sql - SQL Server 中的全局临时表

转载 作者:行者123 更新时间:2023-12-02 11:36:14 24 4
gpt4 key购买 nike

我有一个可以在所有 session 中访问的##表,但有时我会收到错误

There is already an object named '##table' in the database.

为什么以及如何解决它。

最佳答案

发现了一个有趣的引用(过时的 URL 引用了现已删除的恶意网站。):

Global temporary tables operate much like local temporary tables; they are created in tempdb and cause less locking and logging than permanent tables. However, they are visible to all sessions, until the creating session goes out of scope (and the global ##temp table is no longer being referenced by other sessions). If two different sessions try the above code, if the first is still active, the second will receive the following:

Server: Msg 2714, Level 16, State 6, Line 1There is already an object named '##people' in the database.

I have yet to see a valid justification for the use of a global ##temp table. If the data needs to persist to multiple users, then it makes much more sense, at least to me, to use a permanent table. You can make a global ##temp table slightly more permanent by creating it in an autostart procedure, but I still fail to see how this is advantageous over a permanent table. With a permanent table, you can deny permissions; you cannot deny users from a global ##temp table.

关于sql - SQL Server 中的全局临时表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3887989/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com