Which one of below query has better performance? What’s the upside/downside for both query? I want to discuss the scenario for inserting 1000 rows and 100k rows Thanks.
1st
INSERT INTO table_name (col1,col2) VALUES (value1, value2);
INSERT INTO table_name (col1,col2) VALUES (value3, value4);
2nd
INSERT INTO table_name
SELECT (col1,col2)
FROM (
SELECT value1 as col1, value2 as col2 UNION ALL
SELECT value3 as col1, value4 as col2
) A
The second query will perform better because the DB engine has to analyze and execute only one statement.But the difference will be insignificant and will matter only for large inserts (more than 100) But the best approach would be
but your syntax for query 2 should be
INSERT INTO table_name
SELECT col1,col2
FROM (
SELECT value1 as col1, value2 as col2 UNION ALL
SELECT value3 as col1, value4 as col4
) A