tags:

views:

39

answers:

2

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.

+1  A: 

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.

cletus
A: 

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.

Sean Owen