| Goal | This query identifies foreign key relationships that are established using name columns rather than standard identifiers. In a well-designed database, relationships should be built upon stable natural keys (such as codes) or system-generated surrogate keys, rather than mutable textual names. |
|---|---|
| Type | Problem detection (Each row in the result could represent a flaw in the design) |
| Reliability | Medium (Medium number of false-positive results) |
| License | MIT (opens in new tab) |
| Fixing Suggestion | To resolve this issue, refactor the database schema by replacing the name-based foreign key with a robust identifier. Ensure the referenced table has a proper primary key (either a natural code or a surrogate key). Add a corresponding referencing column to the dependent table, migrate the data, and recreate the foreign key constraint using these identifiers. Finally, remove the redundant name column from the dependent table to ensure proper normalization. |
| Data Source | system catalog only |
| SQL Query |
|
Collections
This query belongs to the following collections:
Find problems automatically
Queries, that results point to problems in the database. Each query in the collection produces an initial assessment. However, a human reviewer has the final say as to whether there is a problem or not .
| Name | Description |
|---|---|
| Find problems automatically | Queries, that results point to problems in the database. Each query in the collection produces an initial assessment. However, a human reviewer has the final say as to whether there is a problem or not . |
Categories
This query is classified under the following categories:
Relationships between tables
Queries of this category provide information about how database tables are connected to each other and whether such connections have been explicitly defined and whether it has been done correctly.
Result quality depends on names
Queries of this category use names (for instance, column names) to try to guess the meaning of a database object. Thus, the goodness of names determines the number of false positive and false negative results.
| Name | Description |
|---|---|
| Relationships between tables | Queries of this category provide information about how database tables are connected to each other and whether such connections have been explicitly defined and whether it has been done correctly. |
| Result quality depends on names | Queries of this category use names (for instance, column names) to try to guess the meaning of a database object. Thus, the goodness of names determines the number of false positive and false negative results. |