更新时间:2023-09-22 20:46:34
一个临时表可以有3种,#
是最常用的.这是一个仅存在于当前会话中的临时表.与此等效的是 @
,一个声明的表变量.这具有较少的功能"(如索引等),并且也仅用于当前会话.##
与 #
相同,但范围更广,因此您可以在同一会话中或其他存储过程中使用它.
A temporary table can have 3 kinds, the #
is the most used. This is a temp table that only exists in the current session.
An equivalent of this is @
, a declared table variable. This has a little less "functions" (like indexes etc) and is also only used for the current session.
The ##
is one that is the same as the #
, however, the scope is wider, so you can use it within the same session, within other stored procedures.
您可以通过多种方式创建临时表:
You can create a temp table in various ways:
declare @table table (id int)
create table #table (id int)
create table ##table (id int)
select * into #table from xyz