2.6 KiB
2.6 KiB
DATABASE MODELING CONVETION
Naming
- Table names are written in combination, with the following rules:
- Basically uses
PascalCase - An underscore is used in
derived-table, separating the original name and the derived name. - A derived table is a table derived from another table but not used in the main flow of the business process.
- Examples of derived table implementations include:
- Archiving, for example:
Transaction_2019, is an archive of theTransactiontable for the year2019. - Trashing for deleted data, for example:
Transaction_deleted, stores data from the deletedtransactiontable. - History for storing historical information, for example:
ProductStock_History, stores historical data from theProductStocktable.
- Archiving, for example:
- Basically uses
- Columns are written in combination, with the following rules:
- Basically, uses
PascalCase - Use underscores to represent relationships
object-attributeortable-column
Example:User_Idrepresents theUserobject and theIdattributeBestProduct_Coderepresents theBestProductobject and theCodeattribute- When more than one column has a similar definition, a
prefixcan be added to indicate the column's purpose.
Example:Admin_User_Idrepresents theAdminof theUserobject and theIdattributeOperator_User_Idrefers to theOperatorof theUserobject and theIdcolumn.
- Basically, uses
- Attributes/properties in JSON (for output purpose) are written in combination, with the following rules:
- Basically uses
camelCase - Using underscores to represent relationships
object-attributeortable-column
Example:user_idrepresents theUserobject and theIdattribute.bestProduct_coderepresents thebestProductobject and thecodeattribute.- When more than one column has a similar definition, a
prefixcan be added to indicate the column's purpose.
Example:admin_user_idrefers to theadminof theuserobject andidattributeoperator_user_idrefers to theoperatorof theuserobject, columnidnewArrival_bestProduct_coderefers to thenewArrivalof thebestProductobject, columncodefavorite_bestProduct_coderefers to thefavoriteof thebestProductobject, columncode
- Basically uses
Avoiding Circular Dependency
- Prioritize the child due to it's nature to define the foreign key. This means the child is allowed to import main entities that define the table, not the base.
- Parent imports the child's non main entities, can be the base or others depending on the needs.