What is the difference between using
SELECT ... INTO MyTable FROM...
and
INSERT INTO MyTable (...)
SELECT ... FROM ....
?
From BOL [ INSERT, SELECT...INTO ], I know that using SELECT...INTO will create the insertion table on the default file group if it doesn't already exist, and that the logging for this statement depends on the recovery model of the database.
- Which statement is preferable?
- Are there other performance implications?
- What is a good use case for SELECT...INTO over INSERT INTO ...?
Edit: I already stated that I know that that SELECT INTO... creates a table where it doesn't exist. What I want to know is that SQL includes this statement for a reason, what is it? Is it doing something different behind the scenes for inserting rows, or is it just syntactic sugar on top of a CREATE TABLE
and INSERT INTO
.
INSERT INTO
has two key words (select & into) right up front that let the world know this is no ordinary SQL statement, whileSELECT ... INTO
begins, at least, to look like ordinary SQL statement. A small reason to favor the former. – Martin F