| Goal | Use the same mechanism of generating surrogate key values throughout the database. The use of SERIAL notation/explicitly creating a sequence generator and declaration of a column as an identity column will cause the creation of an external and internal sequence generator, respectively. Nevertheless, one should try to stick with using one of the mechanisms in order to cause less confusion. "If you do something a certain way, do all similar things in the same way." (Robert C. Martin, Clean Code) |
|---|---|
| Notes | The query returns information about all the base table columns that have the identity property or the default value is found by using the nextval function if there is at least one base table column with the identity property and one base table column with the default value that is found by using the nextval function. The query takes into account a possibility that a column may be associated with a sequence generator through a domain. |
| 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 (opens in new tab) |
| Fixing Suggestion | Choose one mechanism (SERIAL, identity columns) and use it consistently. |
| Data Source | INFORMATION_SCHEMA only |
| SQL Query |
|
Collections
This query belongs to the following collections:
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 .
| Name | Description |
|---|---|
| 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 . |
Categories
This query is classified under the following categories:
Comfortability of database evolution
Queries of this category provide information about the means that influence database evolution.
Default value
Queries of this catergory provide information about the use of default values.
Inconsistencies
Queries of this catergory provide information about inconsistencies of solving the same problem in different places.
Sequence generators
Queries of this category provide information about sequence generators and their usage.
| Name | Description |
|---|---|
| Comfortability of database evolution | Queries of this category provide information about the means that influence database evolution. |
| Default value | Queries of this catergory provide information about the use of default values. |
| Inconsistencies | Queries of this catergory provide information about inconsistencies of solving the same problem in different places. |
| Sequence generators | Queries of this category provide information about sequence generators and their usage. |
Further reading and related materials:
The corresponding code smell in case of cleaning code is "G11: Inconsistency". (Robert C. Martin, Clean Code)
| Reference |
|---|
| The corresponding code smell in case of cleaning code is "G11: Inconsistency". (Robert C. Martin, Clean Code) |