SQL Server - Unicode Characters...

Associate
Joined
28 Nov 2004
Posts
1,237
Location
Birmingham
Hi guys,
I have a site which is starting to use other languages such as Chinese. I've have had a slight problem with Chinese characters being stored as "?" in the DB but this was fixed by placing N in front of the text on the SQL inserts/updates
i.e. set myField = N'家'

All my relevant text fields are nvarchars in the DB.

My question is this:

I have a single script which builds the SQL statements based on the form details passed to it so my update placing the 'N' before all text fields is across the whole site. Are there any consequences to this for non-unicode chars or will it be ok? Storage space issues? Field length issues I should worry about?

I just wanna make sure I'm covering all bases here :)

Cheers in advance for your help.
 
The 'n' fields store unicode data, which is why they can handle an extended character set.

Because of this they use 2 bytes per character rather than the usual 1. So whereas the limit of a varchar field is 8000 characters, the limit for nvarchar is 4000 and so on.

Therefore if you have a varchar field containing more than 4000 characters you'll have to change it to a ntext field (or nvarchar(MAX) in SQL 2005+), other wise there is no meaningful difference.
 
Back
Top Bottom