1

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

SELECT CONVERT(BIGINT, 'A') col1 INTO #tmp

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.

4

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.

| improve this answer | |

Your Answer

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.