Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Barcode field length

Tags:

barcode

I'm writing some attendance software. Each member will have an ID card with a barcode which they will use to sign in to events. How long should the barcode field be in my database? I'd like to accept Code 39 and Code 128 barcodes. I know these are variable length codes, so what should I set the max length to?

Thanks!

EDIT: My clients will be using a variety of third-party barcode printing tools.

like image 676
bestattendance Avatar asked Apr 18 '10 00:04

bestattendance


2 Answers

There are no constraints on the general Code 128 symbology, but for example, one of application specifications (GS1) sets practical limits:

GS1-128 barcode size characteristics:

  • The maximum physical length is 165.10 millimetres (6.500 inch) including Quiet Zones.
  • The maximum number of data characters in a single symbol is 48.

GS1 General Specifications section 5.4.1: "GS1-128 symbology characteristics".

An example demonstrating size constrains for Code 128 is provided in this answer.

like image 66
guest Avatar answered Oct 17 '22 05:10

guest


Code 128 can do 128 ASCII characters so set the max length to 128 (or higher, it doesn't really matter).

Let me clarify that last statement. Variable text fields will use 1 byte per character (or more for Unicode type fields but let's ignore those for now) plus some overhead. That overhead might be as little as 1-4 bytes or as much as 16 or more depending on the database.

But the point is that if you store 100 characters in a VARCHAR(128) field or a VARCHAR(1000) field it still uses the exact same amount of space.

The only issue you run into is row limits. This too is database dependent. On some for example the entire row can only take up to 64K in size so the sum of all sizes can't exceed that. Other than that it doesn't matter.

like image 28
cletus Avatar answered Oct 17 '22 06:10

cletus