Вопрос

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