字段命名问题
系统范围内使用的列应该如何命名。例如城市。 在城市查找表中,列称为 city_id、city_name。现在,city 用于其他地方,例如事件 - 我将其称为 event_city,它指的是 city_name。然后在用户配置文件中有 user_city ,它再次执行相同的操作。即使它们都是相同的东西,这些都应该根据表被称为相同还是不同?
How should the naming go for colunms used systemwide. For example city.
In city lookup table the colunm is called city_id, city_name. Now city is used in other places like events - I have called it event_city which refers back to city_name. Then in user profile there is user_city which again does the same. Should these all be called the same or different as per the table even though they are all the same thing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您应该使用对引用 city_id 的 Cities 表的外键引用。
无需更改其他表中的名称,只需保留 city_id 外键即可。
You should rather use a foreign key reference to the Cities table referencing the city_id.
No need to change the name in other tables, just stick to the city_id foreign key.
摘自奥马尔·海亚姆的《鲁拜集》:
关于如何做到这一点有很多讨论,但很少达成一致。选择一个可行的方案并坚持下去——一致性可能是最重要的。
我可能会选择:
如果有两列,我只会使用限定名称与单个表中的城市相关:
顺便说一句,我删除了“城市 ID”列,因为您似乎要加入城市名称。但是,您可能最好使用城市 ID 并使用 CityID 将其他表连接到该 ID。这允许相同的城市名称出现在多个州(以美国为中心的示例)中。
From the Rubaiyat of Omar Khayyam:
There are lots of discussions about how to do this and seldom much agreement. Choose a plausible scheme and stick with it - consistency is probably most important.
I would probably go with:
I would only use a qualified name if there were two columns related to City in a single table:
As an aside, I dropped the 'City ID' column since you seemed to be joining to the city name. However, you might be better off with a City ID and having the other tables join to that, using CityID. This allows for the same city name to appear in multiple states, for a US-centric example.
您的命名约定到底是什么并不重要,重要的是您坚持它,但我不建议在事件表 event_city 上命名您的“城市名称”字段。相反,我建议使用 city_name,因为它更清晰。很明显,这是事件的城市名称,因为它在事件表上。
Exactly what your naming convention is is less important than that you stick to it, but I wouldn't recommend naming your 'city name' field on the event table event_city. Instead I'd suggest using city_name, because it's clearer. It's obvious that it's the event's city name, because it's on the event table.
我会将 event_city 更改为 city_id。
(我假设 event_city 将是对城市的引用,并与 city_id 列中的值匹配。)
I would change the event_city to city_id.
(I am assuming that event_city will be a reference to a city, and match the values in the city_id column. )