您没有指定方向是指公共汽车在接近车站还是离开车站时的行驶方向。可以从一个方向接近拐角处或拐角附近的停靠点,然后从另一个方向离开。这在设计中无关紧要,但在根据数据构建路线时会很重要。
假设您有一个停靠点表和一个路线表。您描述的是两者之间的 m-m 关系:Route 由零个或多个 Stops 组成,Stop 可能出现在零个或多个 Routes 中。
但是,现在您想为混音添加方向。这很好,但你必须记住,“方向”是关系的一个属性。 Stop 和 Route 都不能用“方向”来描述。所以交叉表看起来像这样:
create table RouteStops(
RouteID int not null references Routes( ID ),
StopIncr smallint not null -- Stop #1, stop #2, etc.
StopID int not null references Stops( ID ),
Direction char( 2 ) not null, -- 'N', 'W', 'NW', etc
constraint PK_RouteStops primary key( RouteID, StopIncr )
);
因此,如果 Route #15 包含 31 个站点,则此表中将有 31 个条目。
RouteID StopIncr StopID Direction
15 1 417 N
15 2 122 N
15 3 213 E
...
15 17 122 S
...
您需要一个像 StopIncr 这样的字段,以便您可以指定路线中停靠点的顺序:路线的第一站、路线的第二站等。
当公共汽车向相反方向行驶时,第 122 站将作为第三站和第 17 站访问。
更新:
听起来“方向”是 stop 的一个属性,表明它正在或可能被沿该方向的路线使用。这可以通过一个简单的表格来建模。
create table StopDirection(
StopID int not null references Stops( ID ),
Direction char( 2 ) not null, -- 'N', 'W', 'NW', etc,
constraint PK_StopDirection( RouteID, Direction )
);
因此,停靠点可能与一个方向、两个或所有方向相关联。
StopID Direction
15 N
15 S
15 W
所以第 15 站可用于北行、南行和西行路线。