nvarchar(50)和nvarchar(max)的影响 [英] Implications of nvarchar (50) vs nvarchar (max)

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

问题描述

如果下面两个表之间的唯一区别是 nvarchar(50) nvarchar(max),那么下面两个表之间的一般存储和性能差异是什么? ,每个字段中的字符串范围从1到50个字符?这是在SQL Server 2005中。

What are the general storage and performance differences between the below two tables if their only difference is nvarchar(50) vs. nvarchar(max) and the strings in each field range from 1 to 50 characters? This is in SQL Server 2005.

表1

firstname nvarchar (50)
lastname nvarchar (50)
username nvarchar (50)

表2

firstname nvarchar (max)
lastname nvarchar (max)
username nvarchar (max)


推荐答案

p>如果您保证有1到50个字符的字符串,那么跨越长度为X的字符串运行的同一查询将使用varchar(X)vs. varchar(MAX)更快地运行。此外,您不能在varchar(MAX)字段上创建索引。

If you are guaranteed to have strings between 1 and 50 characters, then the same query run across strings of up-to-length X will run faster using varchar(X) vs. varchar(MAX). Additionally, you can't create an index on a varchar(MAX) field.

一旦您的行的长度超过8000个字符,竞争(行基本上被视为TEXT,而不是varchar(n))。虽然这与比较不是非常相关,因为对于长度超过8000的字符串没有varchar(N)选项。

Once your rows have values above 8000 characters in length, then there are additional performance considerations to contend with (the rows are basically treated as TEXT instead of varchar(n)). Though this isn't terribly relevant as a comparison since there is no varchar(N) option for strings of length over 8000.

这篇关于nvarchar(50)和nvarchar(max)的影响的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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