sql-server – SQL Server多用户中的临时表是否安全?

前端之家收集整理的这篇文章主要介绍了sql-server – SQL Server多用户中的临时表是否安全?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
是线程本地的临时表还是服务器的全局临时表?

解决方法

#temp是会话范围
## temp是服务器范围

MSDN:

Local temporary tables are visible
only in the current session,and
global temporary tables are visible to
all sessions

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.

All other local temporary tables are
dropped automatically at the end of
the current session.

Global temporary tables are automatically dropped when the session that created the table ends and all other tasks have stopped referencing them. The association between a task and a table is maintained only for the life of a single Transact-sql statement. This means that a global temporary table is dropped at the completion of the last Transact-sql statement that was actively referencing the table when the creating session ended.

原文链接:https://www.f2er.com/mssql/77535.html

猜你在找的MsSQL相关文章