Nvarchar or varchar what is better use multiply of 2 or rounded full numbers?

老子叫甜甜 提交于 2019-11-30 23:09:22

问题


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


回答1:


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.




回答2:


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. I thinking mainly here of what are now very old versions of MySql. And so sometimes developers will set the column size at 255 to ensure more portability.




回答3:


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.




回答4:


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




回答5:


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



来源:https://stackoverflow.com/questions/1374958/nvarchar-or-varchar-what-is-better-use-multiply-of-2-or-rounded-full-numbers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!