Is it faster to alter multiple columns in the same query?
alter-table, mysql, sql
Solution
Yes, it's faster. You only have to make one call to the database API, and it only has to parse the query once.
However, for `ALTER TABLE` queries, performance usually isn't a concern. You shouldn't be doing this frequently, only when you redesign your schema.
But if your question were about `UPDATE` queries, for instance, it would probably be significant. E.g. you should do:
UPDATE table
SET col1 = foo, col2 = bar
WHERE <condition>;
rather than
UPDATE table
SET col1 = foo
WHERE <condition>;
UPDATE table
SET col2 = bar
WHERE <condition>;
Problem
Is it any faster to add or drop multiple columns in one query, rather than executing a query for each column? For example, is this: ``` ALTER TABLE t2 DROP COLUMN c, DROP COLUMN d; ``` any faster than this? ``` ALTER TABLE t2 DROP COLUMN c; ALTER TABLE t2 DROP COLUMN d; ```