Fully working version of script - needs lots of cleanup though...
SQL Statements generated for populating the database