开发者

C# datatype for storing strings in a table [closed]

开发者 https://www.devze.com 2023-01-04 00:54 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. 开发者_运维技巧 Closed 12 years ago.

which is the best datatype for storing string in a table in sql server?


In SQL Server:

  • VARCHAR(x) for non-Unicode strings
  • NVARCHAR(x) for Unicode strings

For extra long text (more than 4000 Unicode or 8000 non-Unicode characters):

  • VARCHAR(MAX) for non-Unicode strings
  • NVARCHAR(MAX) for Unicode strings

TEXT and NTEXT are deprecated with SQL Server 2005 and should not be used anymore (the NVARCHAR(MAX)/VARCHAR(MAX) also support all string functions, which is a big plus).

For short (less than 10 chars) and fixed elements, like two-character state abbreviations etc., use CHAR(x) / NCHAR(x) instead of VARCHAR. Be aware though: those fields are always padded to the defined length with spaces!

0

精彩评论

暂无评论...
验证码 换一张
取 消