MySQL naming conventions, should field name include the table name?

前端 未结 9 2320
梦谈多话
梦谈多话 2021-02-07 08:59

A friend told me that I should include the table name in the field name of the same table, and I\'m wondering why? And should it be like this? Example:

(Table)         


        
9条回答
  •  醉话见心
    2021-02-07 09:19

    I agree with you. The only place I am tempted to put the table name or a shortened form of it is on primary and foreign keys or if the "natural" name is a keyword.

    Users: id or user_id, username, password, last_login_time
    Post: id or post_id, user_id, post_date, content
    

    I generally use 'id' as the primary key field name but in this case I think user_id and post_id are perfectly OK too. Note that the post date was called 'post_date" because 'date' is a keyword.

    At least that's my convention. Your mileage may vary.

提交回复
热议问题