• 0

[MySQL] best field type to use for unknown length data


Question

9 answers to this question

Recommended Posts

  • 0

If the datatypes are anything like SQL Server ones then:

char is fixed size, meaning it will pad with spaces should the content length be less than the field size.

varchar is variable length (hint: var at the beginning ;) ); it contains a pointer to the data rather than the data itself.

How unknown is "unknown length"? Is it likely to be in the order of gigabytes, megabytes, kilobytes? If kilobytes or less then varchar is the best, otherwise go for text. If it isn't text in the first place, then BLOB.

  • 0
  mrbester said:
If the datatypes are anything like SQL Server ones then:

char is fixed size, meaning it will pad with spaces should the content length be less than the field size.

varchar is variable length (hint: var at the beginning ;) ); it contains a pointer to the data rather than the data itself.

How unknown is "unknown length"? Is it likely to be in the order of gigabytes, megabytes, kilobytes? If kilobytes or less then varchar is the best, otherwise go for text. If it isn't text in the first place, then BLOB.

And if it's an "unknown file size" greater than 64kb then you're going to need to use mediumblob (holds up to 16MB) or largeblob(holds up to 4GB) instead.

  • 0
  Quote
And if it's an "unknown file size" greater than 64kb then you're going to need to use mediumblob (holds up to 16MB) or largeblob(holds up to 4GB) instead.

And this doesn't mean that each row will take up 64kb/16MB/4GB, but it does mean that there is an upper bound on the data size. The size of the row will increase dynamically as you insert larger data.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.