Click here to Skip to main content
15,905,232 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I have columns with Characters Field in my Table
(eg colums: Name,Address,Father_Name,Emailaddres ..etc)

I have declared those column Datatype as Nvarchar(max)
instead of using nvarchar(100),nvarchar(255)

1) so does it affect my database.

2) Any DisAdvantages?
Posted

hi,

if your are going to store more then size 8000 then you can use it,otherwise it effect on Performance.

When you store data to a VARCHAR(100) column, the values are physically stored in the same way. But when you store it to a VARCHAR(MAX) column, behind the screen the data is handled as a TEXT value. So there is some additional processing needed when dealing with a VARCHAR(MAX) value.

see the below

1. You can create an index on the fixed length column but can not create on the nvarchar(max) column. If you are using the column in where clause in your queries the you should always use fixed length column instead of nvarchar(max). This should be enough to use the nvarchar fixed lengthcolumn. I will specify others as well. However, index key length allowed is 900 bytes. Thus any nvarchar column which will exceed this value will cause issue and will be failed.
2. Memory grant could be a big issue where the server is already memroy starved.As expected row size is more the optimizer will
estimates more memory grant and this value will be much higher than actual required and this would be a waste of a resource as precisous as memory.
If you have couple of queries which are using nvarchar(amx) column and sorting is needed then server might have memroy related issues.
This could be a big perf issue.
3. You can not create the indexes online when the table or index has the nvarchar(max) column.
alter index all on nvarcharmax
rebuild with (online=on)
 
Share this answer
 
I'd say: generally - i don't see any disadvantages in using of NVARCHAR(MAX) data field.
I'd say: everything what you do in your life must be logically wellgrounded (reasonable) ;)

I'd answer this way: Is there any reason to store Name, Address, Father_Name, Emailaddres as NVARCHAR(MAX) data type[^]? Please, note that: nvarchar data type is variable-length unicode string data, but max indicates that the maximum storage size is 2^31-1 bytes (2 GB).
 
Share this answer
 
Comments
King Fisher 6-Dec-14 7:34am    
thank you Maciej ;)
King Fisher 6-Dec-14 7:36am    
you mean, its a bad table Design ?
Maciej Los 6-Dec-14 7:53am    
Not necessary...
All what i wanted to say: it depends on many factors, where one of them are requirements.
hi,

if your are going to store more then size 8000 then you can use it,otherwise it effect on Performance.
 
Share this answer
 
Comments
Maciej Los 6-Dec-14 7:13am    
"it effect on Performance" - how?
mudgilsks 6-Dec-14 8:36am    
When you store data to a VARCHAR(100) column, the values are physically stored in the same way. But when you store it to a VARCHAR(MAX) column, behind the screen the data is handled as a TEXT value. So there is some additional processing needed when dealing with a VARCHAR(MAX) value.

see the below

1. You can create an index on the fixed length column but can not create on the nvarchar(max) column. If you are using the column in where clause in your queries the you should always use fixed length column instead of nvarchar(max). This should be enough to use the nvarchar fixed lengthcolumn. I will specify others as well. However, index key length allowed is 900 bytes. Thus any nvarchar column which will exceed this value will cause issue and will be failed.
2. Memory grant could be a big issue where the server is already memroy starved.As expected row size is more the optimizer will
estimates more memory grant and this value will be much higher than actual required and this would be a waste of a resource as precisous as memory.
If you have couple of queries which are using nvarchar(amx) column and sorting is needed then server might have memroy related issues.
This could be a big perf issue.
3. You can not create the indexes online when the table or index has the nvarchar(max) column.
alter index all on nvarcharmax
rebuild with (online=on)
/\jmot 7-Dec-14 5:49am    
move it to the answer.I think will be better. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900