views:

267

answers:

5

Hello,

My question is what is better to use in generating columns in SQL. Should the size of nvarchar (varchar) be multiply of 2 (32, 64, 128) or it's doesn't matter and we can use fully numbers example '100', '50' ?

Thank You very much for answers with reasons

Greeting's to all

+6  A: 

Doesn't make any difference. Use the size appropiate for your data.

For instance SQL Server, if you look at the Anatomy of a Record you'll see that your size translates into record offsets that are dependent on the previous record in the table, null values and other factors, specially with row compression and page compression taken into account. By the time the field is accessed, any resemblance with the original declare size relation, vis-a-vis powers of 2 or powers of 10, is long gone. Also various elements higher on a query execution stack like join operators or sort operators or whatever, also would no benefit from powers of 2 sizes (I have no 'proof' linkes, but is OK if you take my word for it...). Neither does the TDS protocol when marshaling data back to client. And I see little benefit in the client too.

Remus Rusanu
+1  A: 

There's no benefit in having size of (N)VARCHAR columns be a power of 2. Use whatever is suitable for your domain model.

Pavel Minaev
+1  A: 

it doesn't matter, the values of all table columns are strcutured by the engine to fit together on the physical Page

Charles Bretana
+5  A: 

There's no reason to use multiples of 2. Set the field to match the estimated size of your data.

One number that is worth mentioning though is 255. Some database systems have a maximum varchar type of 255, though this is becoming rarer. And so sometimes developers will set the column size at 255 to ensure more portability.

Joel Coehoorn
+2  A: 

I vote that it does not matter. Pick what makes the most sense for your application. Use human readable values. Pick nice names for variables and columns. Only in really extreme cases will you need to tune. When you find out that you need to tune, tune. Until then, go with whatever makes the most sense from a business or human perspective.

Jacob

TheJacobTaylor