I have been thinking about database design lately and I have the following question:
When a type, say a varchar(max), is set for a column is 2GB of space set aside every time a row is inserted?
Or is the space allocated on the server equal to the amount of data in the column?
Thanks!
The
varchardata type in SQL Server and elsewhere means roughly variable-length character data. Themaxor any other constant value represents its upper bound and not its absolute size. So your latter observation is correct:Now, if you define something like
char(200)(notice the lack of var in front of char there) then yes, 200 characters are allocated regardless of how much data (up to 200 chars) you store in that field. The maximum upper bound for thechardata type is 8000, by the way.