Schemacrawler logo

SchemaCrawler

Free database schema discovery and comprehension tool

Entity-Relationship (ER) Modeling with SchemaCrawler

Overview

SchemaCrawler provides features to infer entity-relationship (ER) model information from standard database metadata. While standard JDBC metadata provides information about tables, columns, and foreign keys, it does not explicitly define the nature of the entities or the cardinality of the relationships. SchemaCrawler’s entity modeling features analyze these metadata elements to infer:

Entity Types

SchemaCrawler classifies tables into several entity types:

Foreign Key Cardinality

Cardinality describes how many rows in a target table can be referenced by a row in the source table. SchemaCrawler uses common ER/ UML notation (min..max):

How to Use Entity Modeling Functionality

The EntityModelUtility class provides a simple API to access these inference features.

EntityType entityType = EntityModelUtility.inferEntityType(table);
System.out.println("Entity type: " + entityType.description());
ForeignKeyCardinality cardinality = EntityModelUtility.inferCardinality(foreignKey);
System.out.println("Relationship cardinality: " + cardinality);

You can also check if a foreign key is covered by an index, which is often a prerequisite for efficient joins and certain cardinality types:

OptionalBoolean covered = EntityModelUtility.coveredByIndex(foreignKey);
OptionalBoolean uniqueCovered = EntityModelUtility.coveredByUniqueIndex(foreignKey);