public void updatePrimaryAndForeignKeys(ArrayList<RelationSchema> relations,
	  ArrayList<ForeignKeyConstraint> foreignKeys) {

	// set primaryKey for newly created relation
	for (RelationSchema relation : relations) {
	  RelationUtils.getInstance().resetPrimaryKey(relation);
	}

	// set foreign keys
	for (RelationSchema relation : relations) {
	  for (RelationSchema subRelation : relations) {
		if (relation == subRelation) {
		  continue;
		}
		for (Attribute attr : relation.getAttributes()) {
		  for (Attribute subAttr : subRelation.getAttributes()) {
			if (attr.getName().equals(subAttr.getName())
			    && subAttr.getIsPrimaryKey()
			    && RelationUtils.getInstance().getKey(subRelation)
			        .getAttributes().size() == 1) {
			  foreignKeys.add(new ForeignKeyConstraint(relation.getName(), attr
				  .getName(), subRelation.getName(), subAttr.getName()));
			  attr.setIsForeignKey(true);
			}
		  }
		}
	  }
	}
  }