在此示例中,我有一个名为“Zones”的表
create table stk_zones (
ZoneId int not null auto_increment,
Primary Key (ZoneId),
ZoneName varchar(255),
Height int,
Width int,
Description varchar(255)
);
在这个区域表中,我添加了一些记录:
insert into stk_zones (ZoneName, Height, Width, Description)
values ('Zone A', 100, 200, 'First Zone!'), ('Zone B', 50, 50, 'Second Zone!'), ('Zone C', 50, 100, 'Third Zone!');
显示区域 B 嵌套在区域 A 内部的最佳方式是什么?它们共享相同的属性,因此我想将它们保留在同一个表中。
最好的选择是辅助表,例如:
create table stk_zone_relations (
ZoneRelationId int not null auto_increment,
Primary Key (ZoneRelationId),
ParentZoneId int,
Foreign Key (ParentZoneId) references stk_zones (ZoneId),
ChildZoneId int,
Foreign Key (ChildZoneId) references stk_zones (ZoneId)
);
不确定这种情况下的正确原则。