SteveK
SteveK

Reputation: 37

Database Value And Unit as Two Separate Columns?

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"?

Upvotes: 1

Views: 238

Answers (3)

gbn
gbn

Reputation: 432421

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

Upvotes: 1

Brian Ensink
Brian Ensink

Reputation: 11218

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.

Upvotes: 3

Mitchel Sellers
Mitchel Sellers

Reputation: 63126

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.

Upvotes: 0

Related Questions