使用nvarchar(max)的任何缺点 [英] Any Disadvantages of using nvarchar(max)

查看:627
本文介绍了使用nvarchar(max)的任何缺点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的表中有字符字段的列

(例如colums:Name,Address,Father_Name,Emailaddres ..etc)



我已将那些列数据类型声明为 Nvarchar(max)

而不是使用nvarchar (100),nvarchar(255)



1)所以它会影响我的数据库。



2 )任何DisAdvantages?

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?

推荐答案

我会说:一般情况下 - 我认为使用 NVARCHAR(MAX)没有任何不利之处数据字段。

我会说:你生活中所做的一切必须在逻辑上有良好的基础(合理);)



我会这样回答:有没有理由存储名称地址 Father_Name Emailaddres as NVARCHAR(MAX)数据类型 [ ^ ]?请注意:nvarchar数据类型是可变长度的unicode字符串数据,但 max 表示最大存储大小为2 ^ 31-1字节(2 GB)。
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).






如果您要存储的尺寸超过8000,那么您可以使用它,否则会影响性能。



将数据存储到VARCHAR(100)列时,这些值将以相同的方式物理存储。但是当您将其存储到VARCHAR(MAX)列时,屏幕后面的数据将作为TEXT值处理。因此在处理VARCHAR(MAX)值时需要一些额外的处理。



见下文



1.您可以在固定长度列上创建索引但不能在nvarchar(max)列上创建。如果在查询中的where子句中使用列,则应始终使用固定长度列而不是nvarchar(max)。这应该足以使用nvarchar固定长度列。我也会指定其他人。但是,允许的索引密钥长度是900字节。因此,任何超过此值的nvarchar列都会导致问题并且将会失败。

2.内存授权可能是一个很大的问题,因为服务器已经记忆不足。正如预期的行大小更多是优化器将b / b
估计更多的内存授予量,这个值将远高于实际需要量,这将浪费资源,就像内存一样残缺。

如果你有几个需要使用nvarchar(amx)列和排序的查询然后服务器可能有与memroy相关的问题。

这可能是一个很大的问题。

3.你不能当表或索引具有nvarchar(max)列时,在线创建索引。

在nvarcharmax上更改索引

使用(online = on)重建


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)






如果您要存储的尺寸大于8000,那么您可以使用它,否则会影响性能。


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


这篇关于使用nvarchar(max)的任何缺点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆