private String findTableToPopulate(List<String> populatedTables, List<String> tables, List<ForeignKey> foreignKeys) {
        t: for (String t : tables) { //examine all tables
           if (! populatedTables.contains(t)) { // only if the table has not yet been populated
               fk: for (ForeignKey fk : foreignKeys) {
                   // make sure that there are not target tables of foreign keys that are not yet populated.
                   // This code will have problems with cyclic foreign key constraints.
                   if (fk.sourceTable.equals(t)) {
                       if (! populatedTables.contains(fk.targetTable)) {
                           continue t;
                       }
                   }
               }
               return t;
           }
        }
        return null;
    }