Fix SQL generation scripts to match the hand made ones

[Fixes #46676015] UAA is broken with MySQL 5.1 (RDS)