Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

differences between INSERT select and insert into select?

I often see two styles, INSERT select and insert into select, what are the differences? Are they the same?

I am using SQL Server 2008 Enterprise.

Here are two samples.

INSERT california_authors (au_id, au_lname, au_fname)
SELECT au_id, au_lname, au_fname
FROM authors
WHERE State = 'CA'

http://www.sqlteam.com/article/using-select-to-insert-records

INSERT INTO Store_Information (store_name, Sales, Date)
SELECT store_name, Sales, Date
FROM Sales_Information

http://www.1keydata.com/sql/sqlinsert.html

thanks in advance, George

like image 484
George2 Avatar asked Aug 27 '09 13:08

George2


People also ask

What is the difference between select into and insert into select?

INSERT INTO SELECT vs SELECT INTO: Both the statements could be used to copy data from one table to another. But INSERT INTO SELECT could be used only if the target table exists whereas SELECT INTO statement could be used even if the target table doesn't exist as it creates the target table if it doesn't exist.

Which is faster insert into or select into?

INTO' creates the destination table, it exclusively owns that table and is quicker compared to the 'INSERT … SELECT'. Because the 'INSERT … SELECT' inserts data into an existing table, it is slower and requires more resources due to the higher number of logical reads and greater transaction log usage.

What is insert into select in SQL?

The INSERT INTO SELECT statement copies data from one table and inserts it into another table. The INSERT INTO SELECT statement requires that the data types in source and target tables match. Note: The existing records in the target table are unaffected.

What is the difference between in and into SQL?

The Difference between SELECT INTO and INSERT INTO SELECT INTO creates a new table while INSERT INTO does NOT. For INSERT INTO, the table must exist else you need to create it.


1 Answers

In SQL Server and MySQL, INTO is pure syntax sugar.

No difference.

Oracle and PostgreSQL require this keyword to be present, and, AFAIR, ANSI SQL standards do too.

like image 97
Quassnoi Avatar answered Oct 31 '22 03:10

Quassnoi