Create a temporary table in SQL on the fly

How to create a temporary table without first creating columns?

CREATE TABLE #Yaks ( YakID int, YakName char(30) ) select name from tempdb..sysobjects where name like '#yak%' drop table #yaks 

First you need to define a table.

+4
source share
1 answer

Create a table (temp) with the same columns as the other (without copying data):

 select * into #TempTable from MyTable where 1=0 

Note. No foreign keys, indexes, etc. are created.

+9
source

Source: https://habr.com/ru/post/1434123/


All Articles