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.
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.
No constraints on Code 128 in theory, but for example, one of applied specifications (GS1) sets practical limits:
GS1-128 has a maximum of 48 characters (excluding special characters) OR a maximum of 6.5" (including quiet area). The limit is based upon whichever comes first.
Source: GS1-128 Symbol Specifications
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.
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.
来源:https://stackoverflow.com/questions/2660560/barcode-field-length