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
The key difference between varchar and nvarchar is the way they are stored, varchar is stored as regular 8-bit data(1 byte per character) and nvarchar stores data at 2 bytes per character. Due to this reason, nvarchar can hold upto 4000 characters and it takes double the space as SQL varchar.
Each character of an nvarchar column requires 2 bytes of storage whereas a varchar column requires 1 byte per character. Potentially, varchar will be quicker but that may well mean that you cannot store the data that you need.
5. We should use the CHAR datatype when we expect the data values in a column are of the same length. We should use the VARCHAR datatype when we expect the data values in a column are of variable length.
There is a subtle difference between these two character data types in SQL Server, while both supports variable length, the VARCHAR data type is used to store non-Unicode characters while NVARCHAR is used to store Unicode characters.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With