Is prefixing each field name in a table with abbreviated table name a good practice?

后端 未结 14 2032
-上瘾入骨i
-上瘾入骨i 2020-12-16 19:26

Do you prefix each field in a table with abbreviated table name?

Example:

Table: User

Fields:
user_id
user_name
user_password

Or d

14条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-16 20:20

    It's an awesome practise:

    1. You see what every field means, at least at what domain it is. You can't figure out what amount means (transactions, incomes) — unless they are xac_amount and inc_amount. Most query tools do not output alias along with the field name.
    2. You may use tables aliases, for sure. But SQL does not require them, and by Murphy's law, if it's not required, it won't be used. There is no standard, so one developer will use x as an alias for transaction, another one will use tran and so on.

    In fact, prefixes are just forced tables aliases, so you can easily see what field belongs to what table.

提交回复
热议问题