phpmysqlnomenclature

MySQL tables name guide style


I would like to know which is the more correct way to name the tables and fields in a MySQL database .

And how to differentiate tables that are intermediate tables .

Examples:

Table name: users or user

foreign key columns: user_id or id or user_ID

Table with two words: purchased_point or point_puchased or pointpuchased

Itermediate table (many to many) users_sites or user_sites or usersites

Is there a some "style guide" like: https://www.codeigniter.com/user_guide/general/styleguide.html


Solution

  • All caps. Different words separator is _ underscore.

    Master or parent tables prefix MSTR Child tables prefix MPNG Transaction tables where multiple parents are referred as TRXN

    Post fix all tables as _TBL

    Use singular names for tables as user and not users

    E.g. MSTR_USER_TBL, MPNG_ACCOUNT_TBL, TRXN_CART_ITEM_TBL

    These conventions i follow. Makes simpler to read.