Tuesday, April 03, 2018

When to Use the SELECT...INTO Statement

DZone Database Zone
When to Use the SELECT...INTO Statement
When to Use the SELECT...INTO Statement

We can use SELECT...INTO in SQL Server to create a new table from a table source. SQL Server uses the attributes of the expressions in the SELECT list to define the structure of the new table.

Prior to SQL Server 2005, the use of SELECT...INTO in production code was a performance "code smell" because it acquired schema locks on system tables of the database, causing SQL Server to appear unresponsive while the query was being executed. This is because it is a DDL statement in an implicit transaction, which is inevitably long-running since the data is inserted within the same SQL Statement. However, this behavior was fixed in SQL Server 2005, when the locking model changed.

No comments:

Fun With SQL: Functions in Postgres

DZone Database Zone Fun With SQL: Functions in Postgres In our previous  Fun with SQL  post on the  Citus Data  blog, we covered w...