简体   繁体   English

varchar(max)MS SQL Server 2000,有问题吗?

[英]varchar(max) MS SQL Server 2000, problems?

I've inherited a asp.net website project that currently runs SQL Server 2000 as its backend. 我继承了一个asp.net网站项目,该项目当前运行SQL Server 2000作为其后端。

I've been doing some databases changes on a local copy of the db using SQL Server 2005 Express. 我一直在使用SQL Server 2005 Express在数据库的本地副本上进行一些数据库更改。 I've create a table using varchar(max) columns. 我已经使用varchar(max)列创建了一个表。 They are used to stored snippets of XHTML that are of arbitrary length. 它们用于存储任意长度的XHTML片段。

While browsing around on stackoverflow I came across this: Are there any disadvantages to always using nvarchar(MAX)? 在浏览stackoverflow时,我遇到了以下问题: 始终使用nvarchar(MAX)是否有任何不利之处?

User mattruma says he found out the "hard way" about using varchar(max) on SQL Server 2000. 用户mattruma说,他发现了在SQL Server 2000上使用varchar(max)的“艰难方法”。

What should I use instead of varchar(max) given that the live database runs on SQL Server 2000? 鉴于实时数据库在SQL Server 2000上运行,我应该使用什么代替varchar(max)

Thanks in advance for any help! 在此先感谢您的帮助!

VARCHAR(Max) was introduced in SQL Server 2005, and will not work on SQL Server 2000. You need to use either VARCHAR(8000) assuming that will be big enough. VARCHAR(Max)在SQL Server 2005中引入,在SQL Server 2000上不起作用。您需要使用两个VARCHAR(8000)前提是它足够大。 Otherwise you will need to use TEXT 否则,您将需要使用TEXT

Edit 编辑

Also if you switch to VARCHAR(8000) keep in mind there is a limit that a single row cannot have more then 8060 bytes. 另外,请记住,如果切换到VARCHAR(8000) ,则单行不能有超过8060个字节的限制。 So if you fill up a varchar(8000) table and have a bunch of other large columns you will get an error. 因此,如果您填写varchar(8000)表并有一堆其他大列,则会出现错误。 This is where Text comes in. 这是Text来源。

Text has performance implication because by default it is stored in a separate location, and they keep a pointer in a table. Text具有性能影响,因为默认情况下, Text存储在单独的位置,并且它们将指针保留在表中。 There is a set option which changes this behavior so that text types are kept in the table until they reach a certain size. 有一个set选项可以更改此行为,以便将文本类型保留在表中,直到达到一定大小为止。 If you have mostly small blobs you might want to enable this. 如果您的Blob大多很小,则可能需要启用它。

It sounds like the varchar(MAX) limitations are a moot point if your live DB is SQL Server 2000, which doesn't support them. 如果您的实时数据库是不支持varchar(MAX) SQL Server 2000,那么听起来好像没有什么限制。 If you have more than 8K characters to store you are pretty much left with the only other option, a TEXT column. 如果要存储的字符数超过8K,则剩下的唯一选择就是TEXT列。 However, beware that TEXT columns have a lot of limitations too. 但是,请注意TEXT列也有很多限制。

For example you can't sort or group on them easily, nor can you compare them for equivalency with other columns. 例如,您不能轻松地对它们进行排序或分组,也无法将它们与其他列进行等效性比较。 That is you can't say Select * from mytable where Mytext1 = mytext2 . 那就是你不能说Select * from mytable where Mytext1 = mytext2

Other relevant concerns: 其他相关问题:

  • I'd suggest using an NText or NVarchar column regardless of the way you go to support Unicode. 无论您要支持Unicode的方式如何,我都建议使用NTextNVarchar列。
  • If the table has a lot of other columns and the varchar(8000) column is likely to be frequently close to full, you may have problems with the row limit of 8K. 如果表中还有许多其他列,而varchar(8000)列可能经常接近满,则行限制为8K可能会出现问题。 Keep this in mind too. 也请记住这一点。

使用文本列。

This depends on your needs. 这取决于您的需求。 You can use a TEXT column instead of VARCHAR(MAX) but you have to be sure that your implementation doesn't need to search on that field, as you cannot do like comparisons on TEXT and NTEXT fields. 您可以使用TEXT列而不是VARCHAR(MAX),但是必须确保您的实现无需在该字段上进行搜索,因为您无法像在TEXT和NTEXT字段上进行比较一样。

If you can limit yourself to 8000 characters, I would use a VARCHAR(8000) column to store the information. 如果您可以限制为8000个字符,则可以使用VARCHAR(8000)列来存储信息。

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

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