views:

2883

answers:

2

What is main difference between INSERT INTO table VALUES .. and INSERT INTO table SET?

Example:

INSERT INTO table (a, b, c) VALUES (1,2,3)

INSERT INTO table SET a=1, b=2, c=3

And what about performance of these two?

+4  A: 

As far as I can tell, both syntaxes are equivalent. The first is SQL standard, the second is MySQL's extension.

So they should be exactly equivalent performance wise.

http://dev.mysql.com/doc/refman/6.0/en/insert.html says:

INSERT inserts new rows into an existing table. The INSERT ... VALUES and INSERT ... SET forms of the statement insert rows based on explicitly specified values. The INSERT ... SELECT form inserts rows selected from another table or tables.

Vinko Vrsalovic
+1  A: 

I think the extension is intended to allow a similar syntax for inserts and updates. In Oracle, a similar syntactical trick is "UPDATE table SET (col1, col2) = (SELECT val1, val2 FROM dual)".

bluej100