• diamondgm (10/16/2009)


    Firstly, we assume that the average is the result of an even spread (that the average length is in fact 8.5 - we only need an average of 8 for storage to be a moot point in char vs varchar).

    That's not an assumption, the even spread is explicitly mentioned in the question. Without it, I agree that the question would have been harder (if not impossible) to answer.

    I think our definition of the word 'explicit' differs dramatically. I did not find the question to indicate that the spread was even as a fact.

    Secondly, within SQL Server, the efficiency may be best to use char in that instance, but take in to account the code operations of trimming and I think it becomes debatable.

    I doubt it. Almost all business applications I have seen have their performance tied to an I/O bottleneck, and have the CPU twiddling it's virtual thumbs while waiting for more data to be read or written. Those few cycles the CPU spends to trim trailing spaces won't affect performance at all, it just means one less thumb to twiddle.

    In the cases where this is true (which is most of the time) white space would aversely affect I/O, no? (Maybe I am very wrong here)

    I agree with you on a purist level, but practically, I would go with varchar still simply for the programmers' ease.

    How, exactly, is varchar easier for a programmer?

    Have you never had a programmer complain about having to trim on certain fields and not on others and wishing for a "standard" approach to text data?

    I think you have raised excellent objections to my way of thinking about this problem. And on paper (assuming the average is 8.5), I can not disagree. Though in reality, I would still use varchar(10), if only for the convenience to the programmers at a realatively low performace cost.