字段命名问题

发布于 2024-09-19 12:39:59 字数 177 浏览 5 评论 0原文

系统范围内使用的列应该如何命名。例如城市。 在城市查找表中,列称为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

你的呼吸 2024-09-26 12:39:59

您应该使用对引用 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.

今天小雨转甜 2024-09-26 12:39:59

摘自奥马尔·海亚姆的《鲁拜集》:

我年轻时也曾热切地经常去
博士和圣人,听到了伟大的论点
关于它和关于;但永远
从我去的同一扇门出来。

关于如何做到这一点有很多讨论,但很少达成一致。选择一个可行的方案并坚持下去——一致性可能是最重要的。

我可能会选择:

  • City(Name, ...)
  • Events(..., City, ...)
  • UserProfile(..., City, ...)

如果有两列,我只会使用限定名称与单个表中的城市相关:

  • UserDetails(..., Home_City, ..., Work_City, ...)

顺便说一句,我删除了“城市 ID”列,因为您似乎要加入城市名称。但是,您可能最好使用城市 ID 并使用 CityID 将其他表连接到该 ID。这允许相同的城市名称出现在多个州(以美国为中心的示例)中。

From the Rubaiyat of Omar Khayyam:

Myself when young did eagerly frequent
Doctor and Saint, and heard great Argument
About it and about; but evermore
Came out by the same Door as in I went.

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:

  • City(Name, ...)
  • Events(..., City, ...)
  • UserProfile(..., City, ...)

I would only use a qualified name if there were two columns related to City in a single table:

  • UserDetails(..., Home_City, ..., Work_City, ...)

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.

拿命拼未来 2024-09-26 12:39:59

您的命名约定到底是什么并不重要,重要的是您坚持它,但我不建议在事件表 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.

清风挽心 2024-09-26 12:39:59

我会将 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. )

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文