Goal | Find base tables where all he non-primary key columns are optional. Avoid too many optional columns. You have to be extra careful with NULLs in case of formulating search conditions of data manipulation statements. |
Notes | If NOT NULL is specified through a domain the information of it is still available in the view INNER JOIN INFORMATION_SCHEMA.columns. Thus, there is no need to read a view with the information about domains. |
Type | Problem detection (Each row in the result could represent a flaw in the design) |
Reliability | High (Few or no false-positive results) |
License | MIT License |
Fixing Suggestion | Increase the number of columns that have NOT NULL constraint. It means going back to the requirements and finding out as to whether some attribute or relationship type of an entity type is actually mandatory. A problem is that you cannot add the NOT NULL constraint to a column that already has NULLs in it. In this case you can add a CHECK constraint with the NOT VALID state. "If the constraint is marked NOT VALID, the potentially-lengthy initial check to verify that all rows in the table satisfy the constraint is skipped. The constraint will still be enforced against subsequent inserts or updates (that is, they'll fail unless there is a matching row in the referenced table, in the case of foreign keys; and they'll fail unless the new row matches the specified check constraints). But the database will not assume that the constraint holds for all rows in the table, until it is validated by using the VALIDATE CONSTRAINT option." (https://www.postgresql.org/docs/current/sql-altertable.html |
Data Source | INFORMATION_SCHEMA only |
SQL Query |
|
SQL statements that help generate fixes for the identified problem.
SQL Query to Generate Fix | Description |
---|---|
| Add the NOT NULL constraint. Most probably only a subset of the statements has to be executed. |
| Add the NOT VALID CHECK constraint. Most probably only a subset of the statements has to be executed. |
This query belongs to the following collections:
Name | Description |
---|---|
Find problems about integrity constraints | A selection of queries that return information about the state of integrity constraints in the datadabase. Contains all the types of queries - problem detection, software measure, and general overview |
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 . |
This query is classified under the following categories:
Name | Description |
---|---|
Comfortability of data management | Queries of this category provide information about the means that have been used to make the use or management of database more comfortable and thus, more efficient. |
Missing data | Queries of this category provide information about missing data (NULLs) in a database. |
Validity and completeness | Queries of this category provide information about whether database design represents the world (domain) correctly (validity) and whether database design captures all the information about the world (domain) that is correct and relevant (completeness). |