July 23, 2011 at 10:27 pm
I ran the below command
create table Ref_organization
( Orgkey int,
Organizationreference nvarchar(100)
The Organizationreference when I run sp_help 'Ref_Organization'
shows nvarchar(200)
Below is the o/p:
Orgkeyintno410 0 yes(n/a)(n/a)NULL
Organizationreferencenvarcharno200 yes(n/a)(n/a)SQL_Latin1_General_CP1_CI_AS
Why is the length 200?
July 24, 2011 at 6:43 am
From Books On Line - emphasis added
nchar [ ( n ) ]
Fixed-length Unicode character data of n characters. n must be a value from 1 through 4,000. The storage size is two times n bytes
Sp_Help is returning the storage size ....
July 24, 2011 at 10:44 am
To add to BitBucket's answer... it takes two bytes to represent 1 character in NVARCHAR which is really "Unicode" of sorts. The first byte indicates the "country code" (or dialect) and the second byte indicates the "character code".
That's not an entirely accurate answer because there's so much more to Unicode but it's the easiest to understand answer. 🙂
--Jeff Moden
Change is inevitable... Change for the better is not.
July 27, 2011 at 2:25 pm
Jeff, I figure you were trying to dilute things a bit here, which I do too depending on the forum as it were, but I want to make sure we aren't feeding any myths.
Jeff Moden (7/24/2011)
To add to BitBucket's answer... it takes two bytes to represent 1 character in NVARCHAR which is really "Unicode" of sorts.
"Unicode" is generic and ambiguous. Microsoft diluted the concept for us and now we're stuck with "Unicode" until we peel the onion, which I won't try to do here. I'll just point to Books Online. SQL Server uses the UCS-2 character encoding/set for "Unicode" columns. Read more here.
The first byte indicates the "country code" (or dialect) and the second byte indicates the "character code".
Where can I read more about this little nugget? UCS-2 maps directly to the BMP meaning 2-bytes per character and no surrogate pairs. I don't know of any way to derive the langauge based soley on the value of the first or second byte. Read more about the BMP here.
There are no special teachers of virtue, because virtue is taught by the whole community.
--Plato
July 27, 2011 at 4:59 pm
opc.three (7/27/2011)
Jeff, I figure you were trying to dilute things a bit here, which I do too depending on the forum as it were, but I want to make sure we aren't feeding any myths.
That's precisely why I said...
That's not an entirely accurate answer because there's so much more to Unicode but it's the easiest to understand answer.
🙂
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply