question

@SQLShark avatar image
@SQLShark asked

Storing numbers as CHAR where no calculation will ever happen

Hello everyone, I guess this is more of a best practice question. When you have data which contains numbers that will never be used for any aggregation should you store them as an INT or CHAR? An example would be userID - 1234 (this will always be a number). Thanks in advance
best-practice
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Kev Riley avatar image
Kev Riley answered
If the data is a true number then I would use the relevant numeric datatype, i.e. INT, but if the data looks like a number but isn't e.g. 0123 - storing this as int would lose the leading 0 - then I would store as character. That's just driven by the efficiencies of storing/handling integers over character data.
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

@SQLShark avatar image @SQLShark commented ·
Thanks Kev.
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.