Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server Insert Without INTO

This may be a really basic SQL question, but I have seen a SQL INSERT statement without the clause INTO and I was wondering if that is some special case in SQL Server 2000 or 2008.

The INSERT statement look something like

INSERT <table_name>
(
  column names
)
select *
from <another table>
where <condition>

Sorry, if this is super basic, but I just wanted to make sure. Thanks!

like image 898
Abe Avatar asked Mar 22 '11 23:03

Abe


People also ask

Is into required with insert SQL?

INSERT INTO is the standard. Even though INTO is optional in most implementations, it's required in a few, so it's a good idea to include it to ensure that your code is portable. You can find links to several versions of the SQL standard here.

What is difference between insert and insert into?

If you are using Insert or Insert into both will insert the data in Table. However Insert into is basically used to fatch the data from another table using select command and insert into table where you want to insert the data.

Is select into faster than insert 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.

How can you insert data into a table without using insert command in SQL?

Your best bet is to copy-paste the data from the Word document into a text file and then use perl, python, java, etc. to generate your insert statements.


2 Answers

The INTO is optional. It is required in ANSI sql but the MS/Sybase developers decided to make it optional.

like image 67
jimconstable Avatar answered Sep 17 '22 11:09

jimconstable


Check the BNF grammar http://savage.net.au/SQL/

92, 99, SQL:2003

<insert statement> ::= INSERT INTO <insertion target> <insert columns and source>

According to the ANSI spec, INTO should only be optional in a MERGE clause.

For SQL Server (this link from 2000 to show how old it is - it exists from the first version of SQL Server), it is optional. It is also optional for MySQL.

INSERT [ INTO]
    { table_name WITH ( < table_hint_limited > [ ...n ] )
        | view_name
        | rowset_function_limited
    }

    {    [ ( column_list ) ]
        { VALUES
            ( { DEFAULT | NULL | expression } [ ,...n] )
            | derived_table
            | execute_statement
        }
    }
    | DEFAULT VALUES 
like image 35
RichardTheKiwi Avatar answered Sep 20 '22 11:09

RichardTheKiwi