Skip to content
Advertisement

Best way to create a temp table with same columns and type as a permanent table

I need to create a temp table with same columns and type as a permanent table. What is the best way to do it? (The Permanent table has over 100 columns)

i.e.

Usually I create table like this.

DECLARE  #TT TABLE(              
  member_id INT,    
  reason varchar(1),    
  record_status varchar(1) ,    
  record_type varchar(1)    
 ) 

But is there any way to do it without mentioning the column names and type, but mention the name of another table with the required columns?

Advertisement

Answer

select top 0 *
into #mytemptable
from myrealtable
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement