简体   繁体   English

处理性能和使用数据类型

[英]Handling performance and using data types

I have some web forms that contain approx 100 to 150 text fields. 我有一些Web表单,包含大约100到150个文本字段。 So, in most of the fields a user can enter a great amount of string data. 因此,在大多数字段中,用户可以输入大量的字符串数据。 I had previously entered VARCHAR(150) , which will not be large enough. 我之前输入过VARCHAR(150) ,它不够大。

So, my question is, which is better to use: VARCHAR(MAX) or TEXT ? 所以,我的问题是,哪个更好用: VARCHAR(MAX)TEXT I am using SQL Server 2008 R2. 我正在使用SQL Server 2008 R2。

There are many related questions available on Stack Overflow, but I am still confused. Stack Overflow上有很多相关的问题,但我仍然感到困惑。 Assuming web forms with more than 50 fields with the TEXT datatype, will that cause any performance-related issues, or make our DB very large? 假设具有TEXT数据类型的超过50个字段的Web表单会导致任何与性能相关的问题,或者使我们的DB非常大吗? I thought that VARCHAR(MAX) could store up to 8000 characters maximum, but I have some fields that can have more than 8000 characters. 我认为VARCHAR(MAX)最多可以存储8000个字符,但我有一些字段可以有超过8000个字符。

Please guide... 请指导......

If you're using SQL Server 2005 or newer use varchar(MAX). 如果您使用的是SQL Server 2005或更新版本,请使用varchar(MAX)。 Text datatype is deprecated and should not be used for new development work. 不推荐使用Text数据类型,不应将其用于新的开发工作。

see also: http://msdn.microsoft.com/en-us/library/ms187993%28v=sql.90%29.aspx 另见: http//msdn.microsoft.com/en-us/library/ms187993%28v=sql.90%29.aspx

To answer your extra questions in the comments: 8000 is the maximum you can enter in a default varchar(x) type. 要在注释中回答您的额外问题:8000是您可以在默认varchar(x)类型中输入的最大值。 This is because you can get maximum 8000 characters in a 'data-page'. 这是因为您可以在“数据页”中获得最多8000个字符。 But with varchar(max) you can store up to 2^31-1 bytes as @Doug_Ivison allready mentioned. 但是使用varchar(max),你可以存储最多2 ^ 31-1个字节,因为已经提到了@Doug_Ivison。 Consequently as soon as the amount of characters is greater than 8000 you'll need multiple pages to contain your data. 因此,只要字符数大于8000,您就需要多个页面来包含您的数据。 The same is valid for a 'text' type. 这同样适用于“文本”类型。 It also will need multiple pages for this amount of data. 此数据量还需要多个页面。 So please don't use text. 所以请不要使用文字。 Besides the fact it's deprecated it doesn't support the things varchar(max) does, like ability to search & index. 除了它被弃用之外,它不支持varchar(max)所做的事情,比如搜索和索引的能力。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM