CodeIgniter Forums
MySQL Field Length - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: MySQL Field Length (/showthread.php?tid=31431)



MySQL Field Length - El Forum - 06-18-2010

[eluser]insub2[/eluser]
Can anyone explain to me in simple, direct terms why it's not a good idea to make the length of all my fields really big, say 255. I've read that I should only have them as long as they need to be but no one is really giving a good reason. AFAIK, there isn't any space saved. So what is the reason?


...it's easier to just put 255 than to think about how long things will need to be. :-P


MySQL Field Length - El Forum - 06-18-2010

[eluser]Ener1[/eluser]
Hi Insub2

When you set the length of a field in a database, the field will take that size even when your are not using it, therefore you are making your database heavy and big, full of anused space.

So lets say you set a field like name to 255 and let´s say that a really big long name has 35 letters ( that´s a huge name ), the rest of the 220 spaces will be there ( taken anyway ) even when you don´t use them, imagine the amount of space you are wasting.

Plus the bigger the base the slower the query

Cheers


MySQL Field Length - El Forum - 06-18-2010

[eluser]insub2[/eluser]
Perhaps I should specify that I'm talking about varchar and int. And at least as far as varchar is concerned, it only stores the value--not the trailing space. Note the storage table here http://dev.mysql.com/doc/refman/5.0/en/char.html


MySQL Field Length - El Forum - 06-18-2010

[eluser]slowgary[/eluser]
insub2,

My opinion is... 255 characters is not that much. If, however, you have already determined that you know the length of a field will not exceed a certain number of characters (names are not usually more than 32 characters), you can limit it to this amount. If you feel like making each of your varchar fields 255 characters, do it. You're right about varchar's, they only use as much space as is needed.

I can't speak with authority on the subject, as I haven't a clue about the inner workings of MySQL's engine, but I say it would be nice if they just combined all text type fields into varchar - allowing you to store as much as is needed, however not padding values so they'll only take up the storage that they need to.

Just an opinion.