Simply to clarify, by indicating something similar to VARCHAR(45) means it will take as much as max 45 figures? I recall I been told by someone a couple of years back the number within the parenthesis does not make reference to no of figures, then your person attempted to describe in my experience something quite complicated that we do not understand and didn't remember already.

And what's the main difference between CHAR and VARCHAR? Used to do look at different companies a little and find out that CHAR gives u the max of how big the column which is better for doing things in case your data includes a fixed size and employ VARCHAR in case your data size varies.

But when it offers a superior the max of how big the column of all of the data of the column, is not it better for doing things whenever your data size varies? Particularly if you have no idea how large your computer data size will probably be. VARCHAR must specify the dimensions (CHAR don't actually need right?), is not it more difficult?

You might also need to specify the dimensions with CHAR. With CHAR, column values are padded with spaces to fill the dimensions you specified, whereas with VARCHAR, just the actual value you specified is saved.

For instance:

    char_value CHAR(10),
    varchar_value VARCHAR(10)

INSERT INTO test VALUES ('a', 'b');


The above mentioned will choose "a          " for char_value and "b" for varchar_value

If all of your values are comparable size, the CHAR might well be a better option since it will frequently require less space for storage than VARCHAR. The reason being VARCHAR stores both the size of the worthiness and also the value itself, whereas CHAR can just keep (fixed-size) value.

The MySQL documentation provides a good explanation from the storage needs of the several data types.

Particularly, for any string of length L, a CHAR(M) datatype will require up (M x c) bytes (where c is the amount of bytes needed to keep a personality... this is dependent around the character occur use). A VARCHAR(M) will require up (L + 1) or (L + 2) based on whether M is <=255 or >255.

So, it truly is dependent how lengthy you anticipate your strings to become, exactly what the variation long is going to be.

NB: The documetation does not discuss the impact of character sets around the storage needs of the VARCHAR type. I have attempted to quote it precisely, but my prediction is the fact that you should multiply the string length through the character byte-width too to obtain the storage requirement.

char and varchar really becomes irrelevant for those who have just 1 variable length area inside your table, just like a varchar or text. Mysql will instantly change all char to varchar.

The fixed length/size record can provide you with extra performance, however, you can't use any variable length area types. This is because it will likely be faster and simpler for mysql to obtain the next record.

For instance, should you perform a Choose * FROM table LIMIT 10, mysql needs to scan the table apply for the tenth record. What this means is locating the finish of every record before you discover the finish from the tenth record. But when your table has fixed length/size records, mysql just must be aware of record size after which skip 10 x #bytes.

Knowing a column will have a small, fixed quantity of chars make use of a CHAR, otherwise make use of a varchar. A CHAR column is padded towards the max length.

VARCHAR includes a small overhead (4-8 bytes based on RDBMS), only uses the overhead + the particular quantity of chars saved.

For that values you realize they will be constant, for instance for Telephone Numbers, Zip Codes etc., It's optimal to make use of "char" without a doubt.

The complicated items you don't remember would be that the 45 make reference to bytes, not chars. It's different if you work with a multibyte character encoding. In Oracle you are able to specify bytes or chars clearly.

varchar2(45 BYTE)


varchar2(45 CHAR)