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

后端 未结 5 985
情话喂你
情话喂你 2021-01-07 23:24

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 u

相关标签:
5条回答
  • 2021-01-07 23:26

    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.

    0 讨论(0)
  • 2021-01-07 23:32

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

    0 讨论(0)
  • 2021-01-07 23:33

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

    0 讨论(0)
  • 2021-01-07 23:40

    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.

    0 讨论(0)
  • 2021-01-07 23:46

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

    0 讨论(0)
提交回复
热议问题