tomdelonge Posted August 1, 2009 Share Posted August 1, 2009 Is the number in parenthesis (I've always used 255) the number of characters that are allowed to fit? If so, I have a md5 hash to store. Should I just set that column to 32? Thanks... Quote Link to comment https://forums.phpfreaks.com/topic/168444-creating-a-varchar-column/ Share on other sites More sharing options...
ldougherty Posted August 1, 2009 Share Posted August 1, 2009 http://dev.mysql.com/doc/refman/5.0/en/char.html The length prefix indicates the number of bytes in the value. A column uses one length byte if values require no more than 255 bytes, two length bytes if values may require more than 255 bytes. Quote Link to comment https://forums.phpfreaks.com/topic/168444-creating-a-varchar-column/#findComment-888562 Share on other sites More sharing options...
BLaZuRE Posted August 2, 2009 Share Posted August 2, 2009 Is the number in parenthesis (I've always used 255) the number of characters that are allowed to fit? If so, I have a md5 hash to store. Should I just set that column to 32? Thanks... Yes, the number in parenthesis is the maximum (for varchar or char). Yes, you can set the column to 32 if it's always going to be a 32 character hash. If you don't use them all, the varchar is adjusted accordingly. In char, it just pads the number to your maximum. I wouldn't set it to 255 unless it's going to be relatively close to that number. If it's something like a phone number, you can set it around 15 (accounting for international and local codes), for a street name, something around 35. Quote Link to comment https://forums.phpfreaks.com/topic/168444-creating-a-varchar-column/#findComment-888648 Share on other sites More sharing options...
fenway Posted August 3, 2009 Share Posted August 3, 2009 Just remember mysql will use the full 255 for any group by or sorting/ordering operations performed on the column, so performance suffers if the value is set too high. Quote Link to comment https://forums.phpfreaks.com/topic/168444-creating-a-varchar-column/#findComment-889977 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.