Barcode field length
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 t开发者_运维技巧o?
Thanks!
EDIT: My clients will be using a variety of third-party barcode printing tools.
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.
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.
These formats can easily encode plenty of digits, surely more than you need for a unique ID. So isn't the question merely, how long are your IDs? Is 10 digits plenty? then 10 characters. Or if they're numeric IDs, you shouldn't even store as a string of characters. Use a numeric SQL type.
The data limit of a Code 128 barcode is 48 Characters.
https://www.premierelectronics.com/blog/barcode-types-identificaton-understanding#accordion-3
Code 39 is restricted to 43 characters. In Full ASCII Code 39 Symbols 0-9, A-Z, ".", "-" and space are the same as their representations in Code 39.
精彩评论