What is the correct SQL DataType to represent my Object?
My object is a string, implemented as an array of 1-50 US-ASCII data characters.
- What SQL Data Type should I use to represent this in my database table?
- I am using SQL Server Express 2008. (Does that matter?)
- Does representing Extended ASCII require a different datatype than represe开发者_高级运维nting Standard ASCII?
If you need a variable length US-ASCII field (up to 50 characters), use VARCHAR(50)
. If you want to use Unicode, you need to use NVARCHAR(50)
.
varchar [ ( n | max ) ]
Variable-length, non-Unicode character data. n can be a value from 1 through 8,000. max indicates that the maximum storage size is 2^31-1 bytes. The storage size is the actual length of data entered + 2 bytes. The data entered can be 0 characters in length. The ISO synonyms for varchar are char varying or character varying.
And:
Objects that use char or varchar are assigned the default collation of the database, unless a specific collation is assigned using the COLLATE clause. The collation controls the code page that is used to store the character data.
nvarchar [ ( n | max ) ]
Variable-length Unicode character data. ncan be a value from 1 through 4,000. max indicates that the maximum storage size is 2^31-1 bytes. The storage size, in bytes, is two times the number of characters entered + 2 bytes. The data entered can be 0 characters in length. The ISO synonyms for nvarchar are national char varying and national character varying.
精彩评论