你如何做你的Nvarchar() [英] How BIG do you make your Nvarchar()

查看:97
本文介绍了你如何做你的Nvarchar()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在设计数据库时,在决定nvarchar的大小时应该考虑什么决定。



如果我要做一个地址表,我的直觉反应将是地址行1为nvarchar(255),像一个旧的访问数据库。



我发现使用这个让我烦恼了旧的字符串将被截断。我知道这可以通过限制输入框来防止,但是如果用户真的有一个超过255的地址行,那么这应该是允许的。



我应该多大使我的nvarchar(????)

解决方案

我的建议:让他们和你真正需要的一样大。



例如。对于邮政编码列,10-20个字符绝对足够。同上一个电话号码。电子邮件可能会更长,50-100个字符。名字 - 好吧,我通常得到50个字符,同名的名字。您可以随时随地扩展字段,如果您真的需要 - 这根本不是一个重大的任务。



真正没有必要使所有的varchar / nvarchar字段大到他们可以。毕竟,SQL Server页面是固定的,每行限制为8060字节。拥有10个字段的NVARCHAR(4000)只是要求麻烦....(因为如果你真的试图填补他们太多的数据,SQL Server将barf在你)。



如果您真的需要一个真正的大字段,请使用NVARCHAR / VARCHAR(MAX) - 只要它们适合,就会存储在您的页面中,如果它们太大,将被发送到溢出存储。 / p>

NVARCHAR vs. VARCHAR:这真的归结到你真的需要异国情调的字符,如日语,中文或其他非ASCII样式的字符?在欧洲,甚至一些东欧的字符不能被VARCHAR领域所代表(他们将被剥夺他们的汉斯(拼写?)西欧语言(英语,德语,法语等)都很好地服务于VARCHAR。



但是,NVARCHAR在任何时候都使用了两倍于磁盘和SQL Server内存的空间,如果你真的需要它,你需要它 - 但是你真的很喜欢?:-)这取决于你。



Marc


When designing a database, what decisions do you consider when deciding how big your nvarchar should be.

If i was to make an address table my gut reaction would be for address line 1 to be nvarchar(255) like an old access database.

I have found using this has got me in bother with the old 'The string would be truncated'. I know that this can be prevented by limiting the input box but if a user really has a address line one that is over 255 this should be allowed.

How big should I make my nvarchar(????)

解决方案

My recommendation: make them just as big as you REALLY need them.

E.g. for a zip code column, 10-20 chars are definitely enough. Ditto for a phone number. E-Mails might be longer, 50-100 chars. Names - well, I usually get by with 50 chars, ditto for first names. You can always and easily extend fields if you really need to - that's no a big undertaking at all.

There's really no point in making all varchar/nvarchar fields as big as they can be. After all, a SQL Server page is fixed and limited to 8060 bytes per row. Having 10 fields of NVARCHAR(4000) is just asking for trouble.... (since if you actually try to fill them with too much data, SQL Server will barf at you).

If you REALLY need a really big field, use NVARCHAR/VARCHAR(MAX) - those are stored in your page, as long as they fit, and will be sent to "overflow" storage if they get too big.

NVARCHAR vs. VARCHAR: this really boils down to do you really need "exotic" characters, such as Japanese, Chinese, or other non-ASCII style characters? In Europe, even some of the eastern European characters cannot be represented by VARCHAR fields anymore (they will be stripped of their hachek (? spelling ?). Western European languages (English, German, French, etc.) are all very well served by VARCHAR.

BUT: NVARCHAR does use twice as much space - on disk and in your SQL Server memory - at all times. If you really need it, you need it - but do you REALLY ? :-) It's up to you.

Marc

这篇关于你如何做你的Nvarchar()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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