Check database schema
check_schemaUse this when the user wants SQL CREATE TABLE statements checked without a drawing, for example "check my schema for broken foreign keys" or "which tables have no primary key". Takes the same DDL text and dialect as make_er_diagram. Returns foreign keys that point to a missing table or column, foreign keys whose referenced columns are not a primary key or UNIQUE, type differences between a foreign key column and the column it references, tables without a primary key, duplicate table and column names (with the name rule used), and the statements it skipped with line numbers. Draws nothing and makes no files. Does not connect to a database or check data.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ddl | Yes | The SQL DDL text: CREATE TABLE statements with columns, types, NOT NULL, PRIMARY KEY, UNIQUE and REFERENCES / FOREIGN KEY, up to 200,000 characters, e.g. "CREATE TABLE users (id int PRIMARY KEY, email text NOT NULL UNIQUE); CREATE TABLE orders (id int PRIMARY KEY, user_id int NOT NULL REFERENCES users(id));". Other statements are listed as skipped. | |
| dialect | No | Which SQL quoting and type names to read: auto (default; accepts "x", `x` and [x]), postgres, mysql or sqlite. It also sets how names are matched: postgres folds unquoted names to lower case and keeps quoted names exact; the others ignore case. Example: postgres. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| notes | Yes | ||
| ready | Yes | ||
| shown | No | ||
| counts | Yes | ||
| issues | Yes | ||
| limits | Yes | ||
| dialect | Yes | ||
| skipped | Yes | ||
| name_rule | Yes | ||
| tables_without_primary_key | Yes |