The question of using a transaction is already discussed in my comment. It is not possible to enclose all 12 steps in a transaction, because step #1 `PRAGMA foreign_keys = off` is a no-op within a transaction as documented at <https://www.sqlite.org/pragma.html#pragma_foreign_keys>.