Brett
Brett

Reputation: 20049

Fixed length numeric value - BIGINT or CHAR data type?

I have a couple numeric fields which will be storing fixed length numeric values, I don't need to do any math on these fields or sorting by highest to lowest or anything like that, so I'm wondering if using the CHAR data type would be better than using a BIGINT?

Upvotes: 0

Views: 503

Answers (2)

Melanie
Melanie

Reputation: 3111

If the data is numeric, use a numeric field. You never know when your requirements will change and you'll need to do numeric processing on the field.

Upvotes: 0

Gordon Linoff
Gordon Linoff

Reputation: 1269443

If you have a fixed-width number and it fits in a decimal field, then use that data type. Something like decimal(15, 0) should give you want you want.

If the choice is between a fixed width character and a string, I would probably go with a string in this case. I find that char(15) makes more sense than storing a 15-digit number in a bigint field. This makes it clear that the field is really an identifier of some sort, rather than an actual number.

Upvotes: 2

Related Questions