Sql & shell scripts to create everything in one pass