checkModifyTable();
checkCreateForeignKey(c);
Constraint uniqueConstraint =
c.core.mainTable.getUniqueConstraintForColumns(c.core.mainCols);
Index mainIndex = uniqueConstraint.getMainIndex();
uniqueConstraint.checkReferencedRows(session, table);
boolean isForward = false;
if (c.core.mainTable.getSchemaName() == table.getSchemaName()) {
int offset = database.schemaManager.getTableIndex(table);
if (offset != -1
&& offset
< database.schemaManager.getTableIndex(
c.core.mainTable)) {
isForward = true;
}
} else {
isForward = true;
}
HsqlName indexName = database.nameManager.newAutoName("IDX",
table.getSchemaName(), table.getName(), SchemaObject.INDEX);
Index refIndex = table.createIndexStructure(indexName, c.core.refCols,
null, null, false, true, isForward);
HsqlName mainName = database.nameManager.newAutoName("REF",
c.getName().name, table.getSchemaName(), table.getName(),
SchemaObject.INDEX);