The difference is not hidden - simply your examples don't illustrate it :-)
Using INSERT TableName (Column1, Column2) VALUES ...
syntax limits your options to values lists (as in your examples; note that the value list should be enclosed in parentheses.) or return value of stored procedure e.g.
INSERT INTO Cities (Location) VALUES ( dbo.CreateNewPoint(x, y) );
Using INSERT TableName (Column1, Column2) SELECT ...
syntax is much more powerful. In addition to cases above you can insert almost any result of SELECT
statement if only it matches target columns types.
In particular you can insert data from other tables, mix values from multiple tables with constant values etc. For example:
INSERT INTO TargetTable (name, ColumnA, ColumnB, Sum)
SELECT 'Programmers', T1.Value, T2.Value, SUM(T1.Value, T2.Value)
FROM SourceTable1 T1, SourceTable2 T2 WHERE T1.Value > 0 AND T2.Value > 0;
Please note that INTO
is an optional keyword that can be used between INSERT
and the target table.
Reference: https://msdn.microsoft.com/en-us/library/ms174335.aspx
SELECT
in anINSERT
if you're not doing aSELECT INTO
?