HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

Are temp tables automatically created when referencing to them?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
tablesarecreatedtempautomaticallyreferencingwhenthem

Problem

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?

Solution

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.

Context

StackExchange Database Administrators Q#124304, answer score: 7

Revisions (0)

No revisions yet.