dvcolgan
dvcolgan

Reputation: 7728

What MySQL data type to use to store the text of a multiple choice test?

I'm writing a multiple choice test taking app and wondering what he most appropriate data type would be for storing a question's question text (and also the answers). A question's text is probably going to usually be less than say 255 characters, but occasionally it might go over that. Taking both performance and memory usage into account, is a TEXT field the best choice, or a TINYTEXT or something else?

Upvotes: 0

Views: 2222

Answers (2)

Roman
Roman

Reputation: 10403

Unless you will be dealing with thousands of questions the performance gain from choosing the right column type will be marginal and unnoticeable. Also correct column indexing will get you a long way before performance becomes an issue. However varchar fields will almost always be a faster column because there are some overheads to having TEXT columns.

Also something else to note about varchar(255) vs tinytext(255) is the size. varchar(255) can hold 255 characters. tinytext(255) can hold 255 bytes. Note the subtle difference, especially when running with utf8. This means that the former may hold more stuff.

On the other hand if you don't have a large amount of records to think about then you should really focus on whether a varchar(255) column will be enough space to accommodate any size question length, because at the end of the day if you can't fit all your questions in 255 characters, then you have no choice but to move to a larger column.

Upvotes: 0

Fantius
Fantius

Reputation: 3862

If it may go over 255 then you should use varchar(10000) or something like that. Any varchar larger than varchar(255) is stored in exactly the same way. The Text data type has some performance considerations that you don't need to worry about if you simply don't use it.

Upvotes: 1

Related Questions