Consolidate ALTER statements and remove subquery within DELETE.

MySQL won't allow a DELETE with a subquery on the same table in case of
cycles, so we need to execute the subquery separately. We also combine
ALTER statements on the same table to let the database optimize the
operation.