tags:

views:

350

answers:

3
+1  Q: 

nvarchar(256)....?

Why does nvarchar(256) seem to the be the standard for user names in SQL Server?

Any system functions that return a user name return nvarchar(256), the ASP Membership provider uses nvarchar(256)

256 seems like an odd number (yes, I know its even...) - 255 I could understand (1 byte address) but 256 doesn't make sense to me.

Can anyone explain?

+7  A: 

As programmers we automatically count starting at 0, but in this case nvarchar(0) would mean no characters. Turns out that 256 is your nice round number 2^8.

Rich
Wait... I might be showing my ass, but if its an nvarchar, that means each is a unicode char. Each char is 16 bits (nvarchar -> utf-16??), so 256*16 = 4096 bits or 512 bytes? Am I wrong?
Will
(of course, *varchars hold only what's in them; nchar(256) would take up 512 bytes in the database)
Will
Yes, of course you're right. I was thinking "256 possibilities fits in one byte, that's the 0-255)...
Rich
+1  A: 

2^8 is 256, not 255.

Many times you will see numbering schemes from 0-255 which is 256 numbers when you include the 0.

Brad Barker
A: 

Experience suggests that, across various database over a period of time, 256 seems to be the minimum value for the maximum length of string fields. I wouldn't be surprised if it goes back to dBASE.

le dorfier