views:

42

answers:

3

I want to store a computer's processor speed in a database. Should I use one column as a varchar and store the number and unit together e.g. "1.3 ghz"

or

should I create two separate columns, one as a decimal for "1.3" and a second column for the units as a varchar "ghz"?

A: 

This depends on the function of the data or the desired end result.

if you will be working with them mathematically you might be better off with two fields, but if you are simply storing/returning the value as is, a varchar is just as easy.

Mitchel Sellers
+3  A: 

Consider storing the value in this column with a fixed known unit. For example, make this an integer column store all speeds in this column as raw mega-hertz. This would let you write code that formats and presents the value to the user outside of the database.

Brian Ensink
I agree, it is all about knowing your data. If you will never have data below a MHz then do as suggested. I would possible even store everything on the Hertz level and do my conversions to Mhz or Ghz as needed in application.
Dustin Laine
Surely you meant hertz - that's the base unit. Some things even run in kHz.
Adam Musch
@Adam Musch, Ha ha yes I wrote that at first but I changed it because I thought that a typical 32 bit integer field wouldn't have enough range for today's processors. Obviously an appropriate field type and base unit has to be selected.
Brian Ensink
@Adam Munsch: not for 25 years or so...
gbn
@gbn - never bought a watch crystal or timing crystal, have you? They're generally 32 kHz, as are some ultra-low power integrated circuits.
Adam Musch
@Adam Munsch: OP said "computer's processor speed in a database". And I started life as an electronic engineer...
gbn
+1  A: 

At some point you'll want to compare so store it as a integer in megahertz. You only have to look the the questions here where some lucky soul has text to be parsed or sorted as numbers.

GHz etc is client formatting

gbn