Alvin Alvin - 5 months ago 12
SQL Question

Storing long hex value

What is the best way to store long hex string that has more then 1500 chars?

What is the best type?


  1. Byte

  2. Text

  3. LongText

  4. VarChar


Answer
  • BYTE have fixed padding and a maximum length of 255 byte, so it's no good for you.
  • VARCHAR and TEXT have both a maximum length of 65535 bytes (64kB) and uses 2 more extra bytes to store the length of the data.
  • LONGTEXT have a maximum length of 4294967295 bytes (4GB) and uses 4 more extra bytes to store the length of the data.

If you know that you will always have less than 64kB of data in your HEX string, I would choose TEXT, otherwise go with LONGTEXT.