Has SELECT an INSERT clause?

All we need is an easy explanation of the problem, so here it is.

I know the form

Select * into new_table from old_table

statement. Bur recently I found 2 posts here and here which use it like

INSERT INTO PlayerBackups

I find nothing in msdn, is that some new syntax or just a fault? I guess the later because

INSERT INTO PlayerBackups

would work fine.

How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

Both posts are wrong syntax.

I’ve -1 in the first from SO and left a comment on the second.

Create a table

SELECT * INTO PlayerBackups FROM NhlPlayer

Inserts to an existing table

INSERT PlayerBackups SELECT * FROM PlayerBackups

Method 2

INTO new_table
FROM old_table

The above creates a new table based off of the source’s table structure. new_table, in this example, cannot exist or an error will be raised and the statement will not be committed.

INSERT INTO new_table_must_exist
FROM old_table

In this example, it copies data from old_table to new_table_must_exist. Here new_table_must_exist must already exist, and the data mappings have to be compatible.

Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply