Sql server data fields nvchar (x) or nvarchar (max)
varchar (max) won't take up extra space.
One dangerous thing about varchar (max) is that someone could potentially have a huge amount of data. This could harm an attacker. or a faulty program, enters a 1 MB address bar. No client or web application expects this, and it can cause them to crash.
So, as best practice, create varchar fields with the specified maximum length.
a source to share
If you're unsure, and for something like a comment field, which can be quite large, type NVARCHAR(MAX)
is the way to go. If it's for something with a reasonable maximum, like a mailing address, then better than NVARCHAR(100)
.
The used space corresponds to the maximum length of the value that can be placed in it.
What I mean is if you insert a string with 80 characters and then update it with a 40 character replacement, the allocated space can stay up to 80 characters until the database is compact, the table is rebuilt, etc.
a source to share
I'm not sure what you are storing in columns, but you might consider varchar instead of nvarchar. nvarchar stores Unicode data that is used for multilingual data and takes up more space than varchar. If the field will only store English (for example), then it is better to choose varchar.
a source to share