MySQL命名约定,应该字段名包含表名吗? [英] MySQL naming conventions, should field name include the table name?
问题描述
朋友告诉我,我应该在同一个表的字段名称中包括表名,我想知道为什么?应该是这样吗?
例如:
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) Users
(Fields) user_id, username, password, last_login_time
我看到前缀'user_'是无意义的,因为我知道它已经为一个用户。但我也想听到你的声音。
注意:我在php,mysql中编程。
I see that the prefix 'user_' is meaningless since I know it's already for a user. But I'd like to hear from you too. note: I'm programming in php, mysql.
推荐答案
我试图把表名或缩短形式的唯一地方放在主键和外键上,或者如果自然名称是一个关键字。
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
我通常使用'id'作为主键字段名称,但在这种情况下,我认为user_id和post_id也是完全正确的。请注意,发布日期被称为post_date,因为date是一个关键字。
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.
这篇关于MySQL命名约定,应该字段名包含表名吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!