Goal | Find base tables that implement recording multivalued attribute values with the help of repeating group of columns. Find base tables that have more than one columns with the same type and field size and the difference between the columns are the numbers in the column names (column1, column2, etc.). |
Notes | Query assumes that repeating columns have names that differ from each other only by numbers. In case of the string_agg function, the line break (br) tag is used as a part of the separator for the better readability in case the query result is displayed in a web browser. The query excludes columns that have year or month number at the end of the name. |
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 License |
Fixing Suggestion | Instead of repeating groups one should have multiple tables or should use a column with an array type. Create a dependent table or use a column with an array type. For instance, instead of table Photo(photo_id, name, tag1, tag2, tag3) create tables: Photo(photo_id, name) Photo_tag(photo_id, tag, seq) |
Data Source | INFORMATION_SCHEMA only |
SQL Query |
|
This query belongs to the following collections:
Name | 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 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 database evolution | Queries of this category provide information about the means that influence database evolution. |
Database design antipatterns | Queries of this category provide information about possible occurrences of SQL database design antipatterns. |
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. |
Structure of base tables | Queries of this category provide information about the structuring of base tables at the database conceptual level |
Further reading and related materials:
Reference |
---|
This is one of the antipatterns from the Bill Karwin's book of SQL antipatterns. See Chapter 8: Multicolumn Attributes. |
Smell "Multicolumn attribute": Sharma, T., Fragkoulis, M., Rizou, S., Bruntink, M. and Spinellis, D.: Smelly relations: measuring and understanding database schema quality. In: Proceedings of the 40th International Conference on Software Engineering: Software Engineering in Practice, pp. 55-64. ACM, (2018). |