문제

Is it common practice to split the ids between many tables?

Example

+---------------------------+
| load                      | 
+---------------------------+
| load_id                   |
|                           |
+---------------------------+
      |              |
+-----------+ +-------------+
| load_plane| | load_truck  | 
+-----------+ +-------------+
| plane_id  | | truck_id    |
| load_id   | | load_id     |   
|           | |             |
+-----------+ +-------------+
      |              |
+-----------+ +-------------+
| plane     | | truck       | 
+-----------+ +-------------+
| plane_id  | | truck_id    |
|           | |             |   
|           | |             |
+-----------+ +-------------+

The load_id is made up of many product. It can be shipped by plain, train, bus, truck or spaceship oh ya, why not boat too. Just wondering what other peoples thoughts are on this.

도움이 되었습니까?

해결책

In this case you have many to many Relationships between load and plane, load and truck, load and boat. I think its better if you use some type column to identify transport type. So you can do it using 3 tables now.

+---------------------------+
| load                      | 
+---------------------------+
| load_id                   |
|                           |
+---------------------------+

+-------------+
| transport   |
+-------------+
| id          |
| type        |  
|             |
+-------------+

+---------------------------+
| load_transport            | 
+---------------------------+
| load_id                   |
| transport_id              |
+---------------------------+
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top