Simple Varchar Sizing Question (SQL 7.0)

  • I have probably a very simple question about the sizing of a varchar variable.   My book says the max size for a varchar is 8000 characters.  I have a field that I think I can make length 10 without ever having to worry about it again.  However, is there any compelling reason for me not to make it of length 20 instead since since, from what I've read, a varchar will either expand or shrink to the size of the actual data entered.  I'm obviously kind of a novice here so I apologize for the simple nature of the question.

  • As far as I'm aware, from a storage point of view, no it doesn't really matter.  SQL Server will not pad out a varchar column and hence it will only take as much space as it needs (it will also truncate any trailing blanks if you have ANSI_PADDING set to OFF when the column is created).

    The only reason for you to use varchar(10) instead of varchar(20) is to enforce business or data rules - i.e. do you want anything larger than 10 characters to be truncated?  Do you want to limit storage space taken to a maximum of 10 characters for that column?

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply