Wednesday, March 28, 2012

Kinder garden question about datatype

Hi all,

Suppose I know that the maximum length for my customerID field will not be more than 10 characters (95% of times this will be numeric digits like 1000127, while 5% of the times this may be alphanumeric like 1001MT56).

Given this scenario should I use char(10) as the datatype for my customerID field or should I use varchar(10)?
Can you please share your advise from a performance aspect.
BOL has a lot of information but I could not the exact answer to this "kiddy" questions and thus ended up posting this question here.the percentage of numeric/non-numeric doesn't really matter, what's important is the percentage of fully 10 bytes to less than 10 bytes

since 100% of your examples (yeah, i know you gave only two) were less than 10 bytes, i would say use VARCHAR(10)

performance difference should be too small to measure, but your file size will be less with VARCHAR|||About the only times I use CHAR these days is for SSNs, Zip codes, State abbreviations, and occasionally boolean Y/N.|||what size CHAR for zips? will it hold both 5-digit and 9-digit zips?|||I usually use separate 5 and 4 byte columns for the two ZIP components.|||I usually use separate 5 and 4 byte columns for the two ZIP components.How do you deal with postal codes for non-United States addresses?

-PatP|||How do you deal with postal codes for non-United States addresses?most likely he rejects them as not valid|||It is my patriotic duty to impose my belief in nine-digit zip codes upon the rest of the world and liberate them from their godless postal-code systems.

Unless they are an economic trading partner, in which case I just use varchar(20).|||It is my patriotic duty to impose my belief in nine-digit zip codes upon the rest of the world and liberate them from their godless postal-code systems.

Unless they are an economic trading partner, in which case I just use varchar(20).

I like that :D humor when it's most needed!

Or you could quote our moron-in-chief as he says "I am the decider.." and do what ever you want without fear of any consequences .. I bet he added "bite me!" but no one heard it :) oops! .. that's too much politics isn't it? :)

On a lighter note, one of the reasons I am hooked to this forum is the priceless sense of humor that Rudy and the Blind dude have :)

Cheers!|||oops! .. that's too much politics isn't it? :)

don't worry. the other group of talentless corrupt minions of corporate america will be back in power soon.

On a lighter note, one of the reasons I am hooked to this forum is the priceless sense of humor that Rudy and the Blind dude have .

they are just masking their pain.|||don't worry. the other group of talentless corrupt minions of corporate america will be back in power soon.Oh yes, but the problem is which one? There are SO many to choose from!

-PatP|||I assumed he was talking about the Libertarian party...sql

No comments:

Post a Comment