对于公交车时刻表,我应该为所有公交车创建一个数据表并将时间表存储在一列中,还是为每条公交车创建单独的表?

发布于 2025-01-05 01:44:07 字数 137 浏览 4 评论 0原文

我只需要能够显示接下来几辆巴士的到达时间,不打算做任何旅行计划。

对于数据库来说,将每条路线的所有时间都放在一个条目中可能会更快,对吗?尽管这意味着无论日程安排如何,即使他们只需要一些,也需要获得全部内容。

哪种方式会更有效率?

I just need to be able to display the arrival times of the next couple buses, don't plan on doing any trip planning.

Having all the times for each route in a single entry would probably be faster for the database right? Although that would mean whatever's pulling schedules would need to get the whole thing even if they just need a few.

Which way would be more efficient?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

绅士风度i 2025-01-12 01:44:07

最简单的形式是,您需要三张表:一张用于您的公交车,一张用于站点,一张用于时刻表。

create table bus (
    bus_id int -- primary key
,   route_name varchar(64)
)

create table stop (
    stop_id int -- primary key
,   bus_id int references bus(bus_id)
,   address_or_intersection varchar(128)
)

create table timetable (
    time_entry_id int -- primary key
,   stop_id int references stop(stop_id)
,   run_id int
,   stop_time time
)

前两个表是不言自明的。以下是第三张表的示例,该路线具有三个站点,其中一趟在早上运行,一趟在晚上运行:

bus:
bus_id    route_name
------    ----------
   1      red arrow

stop:
stop_id   bus_id   address
-------   ------   ---------
   1         1     Market St
   2         1     North Point
   3         1     Stockton

timetable:
time_entry_id   stop_id   run_id  stop_time
-------------   -------   ------  ---------
    1              1         1     06:15
    2              2         1     06:39
    3              3         1     07:05
    4              1         2     19:03
    5              2         2     19:30
    6              3         2     19:51

In the simplest form, you need three tables: one for your buses, one for their stops, and one for the timetables.

create table bus (
    bus_id int -- primary key
,   route_name varchar(64)
)

create table stop (
    stop_id int -- primary key
,   bus_id int references bus(bus_id)
,   address_or_intersection varchar(128)
)

create table timetable (
    time_entry_id int -- primary key
,   stop_id int references stop(stop_id)
,   run_id int
,   stop_time time
)

The first two tables are self-explanatory. Here is an example of the third table for a route with three stops that makes one run in the morning and one run in the evening:

bus:
bus_id    route_name
------    ----------
   1      red arrow

stop:
stop_id   bus_id   address
-------   ------   ---------
   1         1     Market St
   2         1     North Point
   3         1     Stockton

timetable:
time_entry_id   stop_id   run_id  stop_time
-------------   -------   ------  ---------
    1              1         1     06:15
    2              2         1     06:39
    3              3         1     07:05
    4              1         2     19:03
    5              2         2     19:30
    6              3         2     19:51
请远离我 2025-01-12 01:44:07

当您乘坐第三辆(或更多)公交车时会发生什么?我将创建一个总线表,以通过外键从主路​​由表中引用。

HTH,巴德

What happens when you get the third bus (or more)? I would create a bus table to reference from a main table of routes via foreign key.

HTH, Bud

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