Fixed syntax errors in 20_metadata_templates.sql data file.
Reorganized new database table constraints.

Reorganizing in prep for merging with the rewrite branch.
Having the constraints and indexes added after all tables are created and populated with data is faster.