Query goal: | Find base tables that name starts with a prefix. Do not use prefixes in case of base table names. Derive the names from the names of entity types. Do not use "_", "t_", "tab_", "t11_" etc as prefixes of a table. |
Notes about the query: | In case of finding prefixes the query assumes the use of snake case writing style and that the prefix is separated from the rest of the name by an underscore. The query returns false positive results if the table name starts with a short word (like dog or cat) that is not actually a prefix. |
Query type: | Problem detection (Each row in the result could represent a flaw in the design) |
Query reliability: | Medium (Medium number of false-positive results) |
Query license: | MIT License |
Fixing suggestion: | Rename the table and remove the prefix. |
Data source: | INFORMATION_SCHEMA only |
SQL query: | Click on query to copy it
SELECT table_schema, table_name
FROM information_schema.tables
WHERE table_type='BASE TABLE'
AND table_name~*'^(_|[[:alpha:]]_|(tb|tbl|tab|table|tabel)_|[[:alpha:]][[:digit:]]+_)'
AND 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)
ORDER BY table_schema, table_name; |