Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the data type for barcodes?

I have an Excel CSV file with a Barcode column that has data that looks like this: 5.06E+12 - it has a decimal number(5.06), letter(E) and symbol(+).

When I try to edit this in Excel, the number changes to 5060190000000.

When storing this type of data to my SQL Server database, what should the data type be of my Model's Barcode property?

like image 475
naz786 Avatar asked Feb 15 '17 11:02

naz786


2 Answers

Try to pick the most appropriate data type. If you're using actual product barcodes, a little research indicates that they're likely International Article Numbers.

Since they're really strings of 13 digits, a char(13) would probably be the most appropriate data type to store this data. Don't just default to varchar(50) because that's "big enough" - think of the length specification as free validation.

like image 95
Damien_The_Unbeliever Avatar answered Oct 10 '22 16:10

Damien_The_Unbeliever


This is called E notation which is a variation of scientific notation. The number in question is an integer, but is abbreviated.

5.06 * 10^12 = 5060190000000

Thus, your value should be stored as an integer large enough to store your number.

Your value should be stored as a varchar long enough to fit the length of potential values.

like image 32
Jørgen R Avatar answered Oct 10 '22 14:10

Jørgen R