在SQL Server 2005/2008中创建一个临时表,如当前表

cra*_*ver 6 sql t-sql sql-server stored-procedures

如何创建一个与存储过程中的当前表完全相同的临时表?

Luk*_*Led 15

select * into #temp_table from current_table_in_stored_procedure

#temp_table - locally temp
##temp_table - globally temp

select top 0 * into #temp_table from current_table_in_stored_procedure to have empty table
Run Code Online (Sandbox Code Playgroud)


man*_*nji 7

SELECT * INTO #t FROM table

如果你想要它是空的:

SELECT * INTO #t FROM table WHERE 1 = 2