Catalog of PostgreSQL queries for finding information about a PostgreSQL database and its design problems

AND
AND
ANDQueries of this category provide information about compensating actions of foreign key constraints.
ANDFrom where does the query gets its information?
AND
AND

There are 17 queries.

Seq nrNameGoalTypeData sourceLast updateLicense...
1All foreign key constraintsEnforce referential integrity in database. Find all referential integrity (foreign key) constraints.Generalsystem catalog base tables only2023-12-07 12:48MIT License
2Cascading update is not needed (based on surrogate keys)Find foreign key constraints that reference to a candidate key that is a surrogate key, i.e., its values are generated by the system by using sequence generators. Do not use ON UPDATE CASCADE, ON UPDATE SET NULL, and ON UPDATE SET DEFAULT in case of foreign keys that reference to surrogate keys.Problem detectionINFORMATION_SCHEMA+system catalog base tables2024-11-28 12:31MIT License
3Chains of ON DELETE CASCADEFind all referential paths (chains of of parent-child tables that are associated through foreign key constraints) where all foreign key constraints have ON DELETE CASCADE compensating actions. Be careful with too long chains.Generalsystem catalog base tables only2022-10-29 20:04MIT License
4Foreign keys with ON DELETE CASCADEFind referential constraints (foreign key constraints) that employ ON DELETE CASCADE compensatory action. ON DELETE CASCADE should only be used if it has been created based on a generalization or a composition in the conceptual data model or if the foreign key connects a table that corresponds to the main entity type with a table that corresponds to a non-main entity type.Generalsystem catalog base tables only2020-11-16 10:15MIT License
5Foreign keys with ON UPDATE CASCADEReferential constraints (foreign key constraints) that employ ON UPDATE CASCADE compensatory action. ON UPDATE CASCADE should only be used if the referenced key is a natural key (its values can be changed).Generalsystem catalog base tables only2020-11-15 15:39MIT License
6Inconsistent chain of relationships in terms of using ON UPDATE compensating actionIn case of a chain of relationships between tables (where the primary key and the foreign key have the same columns) the use of ON UPDATE compensating action should be consistent. For instance, in the next example there is inconsistency, because if one changes the person_code in table Person, then the modification does not succeed because it does not cascade to the table Product. It is unclear as to whether it should be possible to change the person_code or not. Person (person_code, surname) Primary key (person_code) Worker(person_code)
Primary key (person_code)
Foreign key (person_code) References Person (person_code) ON UPDATE CASCADE

Product(product_code, registrator)
Primary key (product_code)
Foreign key (registrator) References Worker (person_code) ON UPDATE NO ACTION
Problem detectionsystem catalog base tables only2024-11-28 12:43MIT License
7ON DELETE CASCADE is not needed (based on classifier tables)Find foreign key constraints with ON DELETE CASCADE compensating action that refer to classifier (reference data) tables.Problem detectionINFORMATION_SCHEMA+system catalog base tables2023-12-08 14:52MIT License
8ON DELETE CASCADE is probably missing (based on the multiplicity of the relationship)Find foreign key constraints that completely overlap with a candidate key constraint (primary key or unique constraint) but the foreign key constraint does not have the ON DELETE CASCADE compensating action. In this case there is a foreign key that implements a relationship type between a strong entity type and a weak entity type (1-1 relationship type). Therefore, in this case ON DELETE CASCADE is an appropriate compensating action.Problem detectionsystem catalog base tables only2021-02-25 17:29MIT License
9ON DELETE CASCADE is probably not needed (based on the relationship type)Find foreign key constraints that implement a non-identifying relationship type and have ON DELETE CASCADE compensating action. If the identity of the parent table is not a part of the identity of the child table, then there is a non-identifying relationship type and most probably the foreign key should not have ON DELETE CASCADE.Problem detectionsystem catalog base tables only2023-10-28 18:38MIT License
10ON DELETE SET NULL is probably missingFind implementations of the adjacency list design pattern, where the corresponding foreign key columns are optional but the foreign key constraint does not have ON DELETE SET NULL compensating action. Implement adjacency list correctly.Problem detectionsystem catalog base tables only2021-02-25 17:29MIT License
11ON UPDATE CASCADE is perhaps missing (based on the compensating actions of other foreign key constraints)Find inconsistencies of using ON UPDATE CASCADE in case of foreign key constraints. An example of inconsistency is that there are two foreign key constraints in different tables that refer to the same table and its candidate key. One of the constraints has ON UPDATE CASCADE compensating action one does not. ON UPDATE CASCADE usage should be consistent, otherwise it does not allow us to change key values in the primary table. More generally, there is a set of foreign key constraints F that refer to a candidate key of table T. It cannot be the case that a proper non-empty subset of these foreign keys have ON UPDATE CASCADE compensatory action. Either all the constraints in F should have it or none of it should have it (depending on circumstances).Problem detectionsystem catalog base tables only2022-04-30 18:39MIT License
12ON UPDATE CASCADE is probably missing (based on column names)Find foreign key constraints that do not feature ON UPDATE CASCADE compensating action although people have a reason to change the key value in the primary table by assuming that the names of foreign key columns correctly point towards the use of natural keys in the table.Problem detectionsystem catalog base tables only2023-11-16 11:59MIT License
13ON UPDATE CASCADE is probably missing (based on data types)Find foreign key constraints where the foreign key column does not have an integer type or uuid type and the foreign key constraint does not have ON UPDATE CASCADE compensating action. In this case the foreign key probably refferes to a natural key (i.e., a key that values have meaning outside the computer system) and ON UPDATE CASCADE would be suitable because the key values could be changed over time.Problem detectionINFORMATION_SCHEMA+system catalog base tables2023-10-06 14:19MIT License
14ON UPDATE CASCADE is probably missing (based on the properties of the referenced column)Find the foreign key constraints that do not have ON UPDATE CASCADE and that referenced key is a simple key that has an integer type, is not covered by another foreign key, and does not have an associated sequence generator, i.e., the foreign key references a simple natural key.Problem detectionINFORMATION_SCHEMA+system catalog base tables2022-04-30 18:39MIT License
15SET DEFAULT compensatory action is unsuitableFind foreign keys with SET DEFAULT compensatory action where the foreign key column does not have a default value. Compensatory actions cannot make changes that violate integrity constraints in a database. SET DEFAULT means that there shoud be a default value at the foreign key column.Problem detectionINFORMATION_SCHEMA+system catalog base tables2021-02-25 17:30MIT License
16SET NULL compensatory action is unsuitableFind foreign key constraints that use a SET NULL compensating action but a foreign key column is mandatory, i.e., does not permit NULLs. Compensatory actions cannot make changes that violate integrity constraints in a database. SET NULL cannot put NULL to a mandatory column (delete a foreign key value).Problem detectionINFORMATION_SCHEMA+system catalog base tables2021-02-25 17:30MIT License
17The number of compensating actions of foreign key constraintsFind the number of compensating actions that are specified in case of foreign key constraints.Sofware measuresystem catalog base tables only2020-11-16 10:11MIT License