mssql create temp table Edit

Murugan Andezuthu Dharmaratnam | 23 September 2020 | 657

Creating a temporary table in mssql is one of the easiest things to do. You can use the same syntax as creating a table, the only difference prepend a # to the table name. A temp table will exist in the database only temporarily. Temp table is stored in tempdb which is a system database.

Solution 1

create table #RecipeIngredients
(
	[IngredientName] [nvarchar](128) NULL,
	[Quantity] [nvarchar](64) NULL,
	[UnitName] [nvarchar](64) NULL
)


Solution 2

If I already have a table say SetupCountry with properties NumericId & Name, I can use the select into statement to create the table

select Name,NumericId into #TempCountry
from SetupCountry

select * from #TempCountry


The above query will return the list of countries from the temporary table