Clean up tests

Removed most of the usage of transactions in the tests, replacing with
temporary tables or SELECT literal queries.