Hi, I would like to understand the logic of using "n" in VARCHAR(n). As per my understanding, VARCHAR will occupy the Insert data space only. For Example: For VARCHAR(100), If the Insert data value is "Data", the space occupied is 4, Irrespective of the length specified for "n". Whether n = 100 or n = 200, there is no difference in space occupation. Then What is the need of "n"? Can anyone please explain this. Thanks
The number specifies the maximum size allowed and can be no greater than 8000. Smaller values are helpful to UI developers and also matter greatly for indexes. For example, you might want to index a 2 character code or even a 20 character name, but you can't index a 2000 character string. In fact, the total combined length of all key columns in any clustered or nonclustered index is 900 bytes. Also, when declaring variables, you must specify the length or else it will default to 1 character.