T-SQL – Are Temp Tables Automatically Created When Referenced?

t-sqltemporary-tables

I came across the following script and I am trying to understand it.

select columnA, columnB, columnC
  into #tmpTable
  from tableA

The #tmpTable is referenced after that query, but not before it. There is not a declaration for #tmpTable anywhere in the sql script.

My somewhat general question is:

Will the above create the temp table automatically and why? Is this only for T-SQL or applies generally?

Best Answer

It's not only about Temporary table it's about the INTO Statement in Sql Server. The INTO statement creates a table in the Database and this table is equal to same table we create with Create Table statement.

But this statement does not inherit any constraints.