C# datatype for storing strings in a table [closed]
which is the best datatype for storing string in a table in sql server?
In SQL Server:
VARCHAR(x)
for non-Unicode stringsNVARCHAR(x)
for Unicode strings
For extra long text (more than 4000 Unicode or 8000 non-Unicode characters):
VARCHAR(MAX)
for non-Unicode stringsNVARCHAR(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!
精彩评论