Is there a reason why I should choose a varchar over a text type on a field that is intended to store, let's say an url? It seems that both have variable size so that won't make a difference.

    You would choose "Varchar" for a string that you know will be short.
    You choose "Text" if you want to enter a lot of text

    So an URL goes into a "Varchar" field.

    Edit:
    varchar is only limited to 255 characters

      Thanks for you answer harmor.

        How big?
        BLOB
        TEXT
        A BLOB or TEXT column with a maximum length of 65,535 (216 -1) characters.

          what is the difference between char and varchar?

            Please note that the autotruncation that MySQL does is against the SQL spec, which says you shoudn't truncate chars, but keep the padding upon retrieval. From an application perspective, this makes char and varchar appear pretty much the same.

            From a storage perspective, char is slightly more efficient if you're storing things like md5s that are ALWAYS a certain legnth, since there is no need to store the length in each row, only once in the table definition.

            Generally speaking, char(x) is quite useful when storing things that are always x length, but if it's variable, there's often no savings in space, and sometimes you use more than a varchar(x) would.

              Write a Reply...