开发者

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 wond开发者_开发百科ering 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!


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


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 


From MSDN:

INTO is an optional keyword that can be used between INSERT and the target table.

http://msdn.microsoft.com/en-us/library/aa933206%28v=sql.80%29.aspx


You mention that this comes from an early version of SQL. If you have 2005 onwards running now you can drop the INTO.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜