Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This really depends on how much <code>cabs</code> and <code>trailers</code> have in common. One approach would be the route you have gone down having two fields in your <code>tyre</code> table, you would probably also want a check constraint to ensure that only one is null, and that both are not null to ensure that any tyre has one, and only one parent.</p> <p>Another option would be to store trailers and trucks in a single table, and have a <code>Type</code> field that stores whether it is a truck, or a trailer, then your tyre table only needs a single field to link to the ID of this main table. You will just need to ensure that this table has all the columns that you had in truck and trailer.</p> <p>Another option would be to use inheritance, this would be similar to the single table approach, but if there are not very many overlapping columns between the two types, or non shared children this can be a better approach. So you might have tables like so:</p> <p><strong>Vehicle</strong> { VehicleID (PK), SharedColumn1, SharedColumn2 }</p> <p><strong>Truck</strong> { VehicleID (PK, FK [Vehicle]), TruckColumn1, TruckColumn2 }</p> <p><strong>Trailer</strong> { VehicleID (PK, FK [Vehicle]), TrailerColumn1, TrailerColumn2 }</p> <p><strong>Tyre</strong> { TyreID (PK), VehicleID (FK [Vehicle]), TryeColumn1 }</p> <p><strong>TruckOnlyChild</strong> {ID (PK), VehicleID (FK [Truck]) }</p> <p>Each of the 3 approaches has it's pros and cons, you really need to chose which is preferential to you. For what it is worth, I personally would go for one of the second two options, depending on my requirements. If the attributes were sparse enough I would consider the 2nd option but using EAV instead of having lots of null columns</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload