Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any downside to giving extra size/length to your database columns?

I usually set all my varchars to 255 to be safe. Does it make any difference in terms of the disk space or anything else? Is there any downside to having bigger varchars/ints/other fields than you would mostly need?

like image 251
Ali Avatar asked Apr 28 '11 16:04

Ali


People also ask

Does length of varchar matter?

Yes, is matter when you indexing multiple columns. Prefixes can be up to 1000 bytes long (767 bytes for InnoDB tables). Note that prefix limits are measured in bytes, whereas the prefix length in CREATE TABLE statements is interpreted as number of characters.

How big should my varchar be?

The size of the maximum size (m) parameter of a VARCHAR column can range from 1 to 255 bytes. If you are placing an index on a VARCHAR column, the maximum size is 254 bytes. You can store character strings that are shorter, but not longer, than the m value that you specify.

How many rows in MySQL table is too much?

The MySQL maximum row size limit of 65,535 bytes is demonstrated in the following InnoDB and MyISAM examples. The limit is enforced regardless of storage engine, even though the storage engine may be capable of supporting larger rows.

What is the maximum number of columns in a MySQL table?

MySQL has hard limit of 4096 columns per table, but the effective maximum may be less for a given table. The exact column limit depends on several factors: The maximum row size for a table constrains the number (and possibly size) of columns because the total length of all columns cannot exceed this size.


1 Answers

If you allow 255 characters then someone may use 255 characters. And so every report and online data entry screen has to be able to handle 255 characters. Messy.

I have a real-world example: in our system someone decided that department names could be 200 chars long. When someone put in a rather long value, it screwed up the layout of several HTML forms, pushing other fields off the right hand side and making them inaccessible. So some remedial work was required...

like image 168
Tony Andrews Avatar answered Oct 08 '22 00:10

Tony Andrews