I am using SQL Server 2016 and I tried to the following query.


This query is obviously in error. Because it does not convert. However, the temporary table (#tmp) is created even if the query fails.

Why? I think this is by design, but I want to know why.

PDW (parallel datawarehouse) does not create temporary table.

New contributor
Suseong Park is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

In autocommit mode, SELECT...INTO executes 2 separate transactions. The first creates the table and the second loads the table. The table create will be committed even if the subsequent insert portion of the statement fails.

In old versions of SQL Server, both operations were done in a single atomic transaction but this was notorious for locking system tables and causing excessive blocking.

Your Answer

Suseong Park is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.