Friday, May 23, 2008

Unicode and Large Data Types in SQL Server

Use nvarchar as a datatype in SQL Server 2005 to preserve unicode characters. Compare the following strings,
nvarchar: “hello” éЀЙẅç
varchar: “hello” é???ç

Varchar gets most but not all. Use nvarchar to be safe when working with international symbols.

Here's some good stuff I found on using unicode with SQL Server 2005, pay special attention to the Large-Value Data Types section:

Unicode Basics
The easiest way to manage character data in international databases is to always use the Unicode nchar, nvarchar, and nvarchar(max) data types, instead of their non-Unicode equivalents, char, varchar, and text.

Pasted from http://msdn.microsoft.com/en-us/library/ms187828.aspx


Using Unicode Data
Use of nchar, nvarchar, and ntext is the same as char, varchar, and text, respectively, except that:
· Unicode supports a wider range of characters.
· More space is needed to store Unicode characters.
· The maximum size of nchar columns is 4,000 characters, not 8,000 characters like char and varchar.
· The maximum size for nvarchar columns, using the max specifier, is 2^31-1 bytes. For more information about nvarchar(max), see Using Large-Value Data Types.

Pasted from http://msdn.microsoft.com/en-us/library/ms191200.aspx

Using Large-Value Data Types
Use varchar(max), nvarchar(max), and varbinary(max) data types instead of text, ntext, and image data types.

Pasted from http://msdn.microsoft.com/en-us/library/ms178158.aspx

Storage and Performance Effects of Unicode

Pasted from http://msdn.microsoft.com/en-us/library/ms189617.aspx

0 comments: