I have a question on Database design. Lets assume I want to track equipment location information. The location can be at various buildings. Those buildings can have various floors that hold various departments that are located in various rooms Etc…
Currently I do something like this;
TblBuilding
BuildingID Buildingname
1 Building1
2 Building2
DepartmentTBL
DeparmentID Departmentname
1 Operations
FloorTBL
FloorID FloorName
1 2nd floor
Roomtbl
RoomId Roomname
1 exam12
Equipmenttbl
Equipid BuildingID departmentID floorID RoomID
123456 1 1 1 1
The problem with the above is that equipment location information can require a differing hierarchy then allowed by the above design.
The following design allows for unlimited hierarchy and appears more efficient but is not nearly as practical.
LocationTBL
LocationID Location ParentLocationID
1 Building1 0
2 2nd floor 1
3 Operations 2
4 Exam12 3
5 Building2 0
EquipmentTBl
EquipID LocationID
123456 4
You can see that the equipment is located in exam12, operations, 2nd floor , Building1
To query all of the equipment located in Building1 becomes a major undertaking as I can only get it by recursing thru the locationTbl .
Is it better to stay with the first design or to spend hours writing functions that can extrapolate the data from the later design. Or better still is there a happy median I am overlooking
Currently I do something like this;
TblBuilding
BuildingID Buildingname
1 Building1
2 Building2
DepartmentTBL
DeparmentID Departmentname
1 Operations
FloorTBL
FloorID FloorName
1 2nd floor
Roomtbl
RoomId Roomname
1 exam12
Equipmenttbl
Equipid BuildingID departmentID floorID RoomID
123456 1 1 1 1
The problem with the above is that equipment location information can require a differing hierarchy then allowed by the above design.
The following design allows for unlimited hierarchy and appears more efficient but is not nearly as practical.
LocationTBL
LocationID Location ParentLocationID
1 Building1 0
2 2nd floor 1
3 Operations 2
4 Exam12 3
5 Building2 0
EquipmentTBl
EquipID LocationID
123456 4
You can see that the equipment is located in exam12, operations, 2nd floor , Building1
To query all of the equipment located in Building1 becomes a major undertaking as I can only get it by recursing thru the locationTbl .
Is it better to stay with the first design or to spend hours writing functions that can extrapolate the data from the later design. Or better still is there a happy median I am overlooking