| Goal | Find where a hierarchical structure is implemented in a base table by adding a foreign key that refers to a candidate key of the same table. |
|---|---|
| Notes | The query searches tables that implement a hierarchy based on the adjacency list pattern. |
| Type | General (Overview of some aspect of the database.) |
| License | MIT (opens in new tab) |
| Data Source | system catalog only |
| SQL Query |
|
Collections
This query belongs to the following collections:
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 by overview
Queries that results point to different aspects of database that might have problems. A human reviewer has to decide based on the results as to whether there are problems or not .
| 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 by overview | Queries that results point to different aspects of database that might have problems. A human reviewer has to decide based on the results as to whether there are problems or not . |
Categories
This query is classified under the following categories:
Database design antipatterns
Queries of this category provide information about possible occurrences of SQL database design antipatterns.
Hierarchical data
Queries of this catergory provide information about storing hierarchical data in the database.
Relationships between tables
Queries of this category provide information about how database tables are connected to each other and whether such connections have been explicitly defined and whether it has been done correctly.
Structure of base tables
Queries of this category provide information about the structuring of base tables at the database conceptual level
| Name | Description |
|---|---|
| Database design antipatterns | Queries of this category provide information about possible occurrences of SQL database design antipatterns. |
| Hierarchical data | Queries of this catergory provide information about storing hierarchical data in the database. |
| Relationships between tables | Queries of this category provide information about how database tables are connected to each other and whether such connections have been explicitly defined and whether it has been done correctly. |
| 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 3: Naive Trees. |
| https://blog.duncanworthy.me/sql/hierarchical-data-pt1-adjacency-list/ |
| Sharma, T., Fragkoulis, M., Rizou, S., Bruntink, M. and Spinellis, D.: Smelly relations: measuring and understanding database schema quality. In: 40th International Conference on Software Engineering: Software Engineering in Practice, pp. 55–64. ACM, (2018). https://doi.org/10.1145/3183519.3183529 (Adjacency list) |
| Representing the Status of the Main Entities of an Information System in SQL Databases, Master Thesis, in Estonian. |
| Factor, P.: SQL Code Smells. Redgate, http://assets.red-gate.com/community/books/sql-code-smells.pdf, last accessed 2019/12/29 (Storing the hierarchy structure in the same table as the entities that make up the hierarchy) |
| Dintyala, P., Narechania, A., Arulraj, J.: SQLCheck: automated detection and diagnosis of SQL anti-patterns. In: 2020 ACM SIGMOD International Conference on Management of Data, pp. 2331–2345. (2020). https://doi.org/10.1145/3318464.3389754 (Adjacency List) |