What is the data type for barcodes?

16,851

Solution 1

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.

Solution 2

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.

Share:
16,851

Related videos on Youtube

naz786
Author by

naz786

Graduated after studying Computer Science in 2018 - taught programming using object oriented Java, etc. Gained internship in .NET C# Web Development. I liked it. Decided to do my final year uni project using .NET MVC, C#, Visual Studio, LINQ, other web technologies etc. Graduated. Got a job advertised as Junior .NET MVC developer. Ended up developing UI front ends with CSS for 6 months. Offered a role in Java development, etc. Learnt debugging, how to use IntelliJ, working on defects and being analytical for triage to apply fixes. I want to go back into ASP.NET MVC, C# web development. Started online course in ASP.NET Core an I am currently doing some ASP.NET web application projects whilst job searching.

Updated on September 16, 2022

Comments

  • naz786
    naz786 over 1 year

    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?

    • Gordon Linoff
      Gordon Linoff about 7 years
      You should store this as a string . . . say, varchar(10). Normally, though, a value represented that way is storing a floating point number, which is why you see the full value in Excel.
    • Robin Mackenzie
      Robin Mackenzie about 7 years
    • Bob Jarvis - Слава Україні
      Bob Jarvis - Слава Україні about 7 years
      @aladdin786 - VARCHAR would be an appropriate data type. The length of the field would depend on the amount of data actually encoded in the bar code.
  • iamdave
    iamdave about 7 years
    Depending on the range, potentially a bigint.
  • Damien_The_Unbeliever
    Damien_The_Unbeliever about 7 years
    The maximum number of digits for an int is 10 and even then that range is limited.
  • Jørgen R
    Jørgen R about 7 years
    I edited my answer to reflect that you need an integer large enough to store your number, such as a bigint if the number is sufficiently large.
  • Damien_The_Unbeliever
    Damien_The_Unbeliever about 7 years
    Also, if it's a barcode, it's likely that this should be dealt with as a string of digits. You're not going to add barcodes together or do other maths with them, and leading zeroes may be possible.
  • Jørgen R
    Jørgen R about 7 years
    @Damien_The_Unbeliever You are right. Edited my answer.