views:

32

answers:

1

I'm adding a number of fields to a table that stores information on vessels (ships).

The values are related to fuel consumption.

There are eight values, which at any time four can be used:
At port IFO 180
At port IFO 380
At port MDO
At port MGO
Sailing IFO 180
Sailing IFO 380
Sailing MDO
Sailing MGO

Now, a user can enter a value for at port IFO 180 OR IFO 380 and at port MDO OR MGO, not both. Same applies for sailing values.

I've been going back and forth on the best way to store this data.

The two ways I've come up with are as follows:

First:
A field for fuel type, at port or sailing:
AtPortIFOType, nvarchar(3)
AtPortMFOType, nvarchar(3)
SailingIFOType, nvarchar(3)
SailingMFOType, nvarchar(3)

These fields will contain the respective choices made by the user (180 or 380, MDO or MGO)

A field for consumption value, at port or sailing:
AtPortIFOConsumption, int
AtPortMFOConsumption, int
SailingIFOConsumption, int
SailingMFOConsumption, int

The second way I was thinking of storing these values was to just have a field for each and zero out the other one based on the fuel type the user chooses:

AtPortIFO180, int
AtPortIFO380, int
AtPortMDO, int
AtPortMGO, int
SailingIFO180, int
SailingIFO380, int
SailingMDO, int
SailingMGO, int

I've gone back and forth on this seemingly ten times, which option is the most efficient? Or is there a third option that I don't see?

Thanks!

A: 

Both ways look like they would consume roughly similar space in your database, so the memory implications of either method would not be a great factor.

If you are required to sum up values across records, then your second method might be preferable, as it would be more difficult to accidentally sum IFO180 and IFO360 values, as they would be in different fields.

However the first method looks like it would be more suited to the way users would enter the data, i.e. select a fuel type and enter a consumption value. It also makes it more difficult to enter incompatible figures in your database, if someone was manually adding records to the database.

There's no hard and fast rule here though, so not being familiar with how the data is used, I would not recommend either way above the other.

Patrick McDonald
Yeah, I think I will go with the first method. On the very remote chance that there is ever another IFO or MFO fuel type, that method can easily accommodate it as opposed to having to add another field.
Tom