*.dannyg

Deciphering SQL Server Field Length for N types

Oct
15

N types are used for implementing double-byte character sets.  This is sometimes used in designed consideration.  This can be quite confusing as the SQL Server Management Studio can be misleading or a little bit confusing.

Let’s look at one simple table.

image

Notice Representative_Quote is an nvarchar(500).  So what does this mean?  It means that you can have up to 500 characters in this field that are of any character set. 

What if you are to run an sp_help on this same table?  (Note: The equivalent shortcut key for sp_help in SSMS is Alt+F1).

image

Notice how the length size is 1000.  This size is in bytes. 

So what this is saying is that for every 1 character entered in the field, SQL Server reserves two bytes for the nvarchar type.

 

Technorati Tags: ,