- Learning PostgreSQL 11
- Salahaldin Juba Andrey Volkov
- 346字
- 2021-07-02 13:11:47
Database naming conventions
A naming convention describes how names are to be formulated. Naming conventions allow some information to be derived based on patterns, which helps developers to easily search for and predict the database's object names. Database naming conventions should be standardized across the organization. There's a lot of debate on how to name database objects. For example, some developers prefer to have prefixes or suffixes to distinguish the database object type from the names. For example, you could suffix a table or a view with tbl and vw, respectively.
With regard to database object names, you should try to use descriptive names, and avoid acronyms and abbreviations if possible. Also, singular names are preferred, because a table is often mapped to an entity in a high-level programming language; thus, singular names lead to unified naming across the database tier and the business logic tier. Furthermore, specifying the cardinality and participation between tables is straightforward when the table names are singular.
In the database world, compound object names often use underscores, but not camel case, due to the ANSI SQL standard specifications regarding identifier quotation and case-sensitivity. In the ANSI SQL standard, non-quoted identifiers are case-insensitive.
In general, it's up to the developer to come up with a naming convention that suits their needs; in existing projects, don't invent any new naming conventions, unless the new naming conventions are communicated to the team members. In this book, we use the following conventions:
- The names of tables and views are not suffixed
- The database object names are unique across the database or within schemas
- The identifiers are singular, including table, view, and column names.
- Underscores are used for compound names
- The primary key is composed of the table name and the suffix ID
- A foreign key has the same name of the referenced primary key in the linked table
- The internal naming conventions of PostgreSQL are used to rename the primary keys, foreign keys, identity columns, and sequences
Don't use keywords to rename your database objects. The list of SQL keywords can be found at https://www.postgresql.org/docs/current/static/sql-keywords-appendix.html.
- 黑客攻防從入門到精通(實(shí)戰(zhàn)秘笈版)
- 深度實(shí)踐OpenStack:基于Python的OpenStack組件開發(fā)
- Vue.js前端開發(fā)基礎(chǔ)與項(xiàng)目實(shí)戰(zhàn)
- React Native Cookbook
- Mastering QGIS
- 深入淺出React和Redux
- Extreme C
- PHP 7從零基礎(chǔ)到項(xiàng)目實(shí)戰(zhàn)
- Zabbix Performance Tuning
- Python數(shù)據(jù)可視化之美:專業(yè)圖表繪制指南(全彩)
- Building Slack Bots
- Yii2 By Example
- WCF全面解析
- JavaScript語法簡明手冊
- C語言程序設(shè)計(jì)實(shí)驗(yàn)指導(dǎo)教程