Query goal: | Find base table columns that name refers to the possibility that these are used to register personal names. Although there are very long personal names the general approach is to register a shortened version of these. Thus, a large field size is not a good idea because it would cause usability and security problems. There are persons who only have one name (mononymous persons). Database design must take it into account. |
Notes about the query: | The query considers both column names in English and Estonian. |
Query type: | Problem detection (Each row in the result could represent a flaw in the design) |
Query reliability: | Low (Many false-positive results) |
Query license: | MIT License |
Fixing suggestion: | Increase the field size of the column. In case of having columns given name and surname and either a) make both columns optional (permit NULLs) and declare a CHECK constraint that in case of each row at least one of these values must be registered or b) make column given name mandatory (NOT NULL) and surname optional (permits NULLs). |
Data source: | INFORMATION_SCHEMA only |
SQL query: | Click on query to copy it
SELECT c.table_schema, c.table_name, c.column_name, c.data_type, c.character_maximum_length, CASE WHEN c.character_maximum_length>100 THEN 'Although some names are very long such names are rare and too long field size may cause more problems than it solves' WHEN c.data_type='text' THEN 'Do not forget to put a cap to the length by using a CHECK constraint!' ELSE 'OK' END AS comment_length, c.is_nullable, CASE WHEN c.is_nullable='NO' THEN 'Make sure to accommodate mononymous persons!' ELSE 'OK' END AS comment_nullable FROM information_schema.columns AS c WHERE (c.table_schema, c.table_name) IN (SELECT table_schema, table_name FROM INFORMATION_SCHEMA.tables WHERE table_type='BASE TABLE') AND c.table_schema NOT IN (SELECT schema_name FROM INFORMATION_SCHEMA.schemata WHERE schema_name<>'public' AND schema_owner='postgres' AND schema_name IS NOT NULL) AND c.column_name~*'^[_]*(eesnimi|perenimi|perekonnanimi|firstname|first_name|given_name|givenname|surname|family_name|last_name|lastname)[_]*$' AND (c.character_maximum_length>100 OR c.is_nullable='NO' OR c.data_type='text') ORDER BY c.table_schema, c.table_name, c.ordinal_position; |
Collection name | Collection description |
---|---|
Find problems about base tables | A selection of queries that return information about the data types, field sizes, default values as well as general structure of base tables. Contains all the types of queries - problem detection, software measure, and general overview |
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 . |
Category name | Category description |
---|---|
Field size | Queries of this category provide information about the maximum size of values that can be recorded in column fields |
Missing data | Queries of this category provide information about missing data (NULLs) in a database. |
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. |
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). |