SQL Validation fixes

FIxes for problems detected by Fabian.