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?
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?
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/5.6/en/insert.html says:
Since the syntaxes are equivalent (in MySQL anyhow), I prefer the
INSERT INTO table SET x=1, y=2
syntax, since it is easier to modify and easier to catch errors in the statement, especially when inserting lots of columns. If you have to insert 10 or 15 or more columns, it's really easy to mix something up using the(x, y) VALUES (1,2)
syntax, in my opinion.If portability between different SQL standards is an issue, then maybe
INSERT INTO table (x, y) VALUES (1,2)
would be preferred.And if you want to insert multiple records in a single query, it doesn't seem like the
INSERT INTO ... SET
syntax will work, whereas the other one will. But in most practical cases, you're looping through a set of records to do inserts anyhow, though there could be some cases where maybe constructing one large query to insert a bunch of rows into a table in one query, vs. a query for each row, might have a performance improvement. Really don't know.I think the extension is intended to allow a similar syntax for inserts and updates. In Oracle, a similar syntactical trick is: