mysqlÖÐvarcharºÍcharµÄÇø±ð
mysql ÖÐ varchar ºÍ char Êý¾ÝÀàÐ͵ÄÖ÷ÒªÇø±ðÔÚÓÚ´æ´¢·½·¨£ºchar ÒÔÀο¿³¤¶È´æ´¢£¬¶ø varchar ƾ֤ÏÖʵ×Ö·û´®³¤¶È´æ´¢¡£char Êʺϳ¤¶ÈÀο¿µÄ×Ö·û´®£¬Ë÷Òý²éÕҺͽÏÁ¿²Ù×÷¸ü¿ì£¬µ«´æ´¢¿Õ¼äÆÌÕÅ£»varchar Êʺϳ¤¶È¿É±äµÄ×Ö·û´®£¬½ÚÔ¼´æ´¢¿Õ¼ä£¬µ«Ë÷Òý²éÕҺͽÏÁ¿²Ù×÷¸üÂý¡£Ñ¡ÔñÊý¾ÝÀàÐÍʱӦ˼Á¿Êý¾Ý³¤¶È¡¢ÐÔÄܺʹ洢ЧÂÊ¡£
VARCHAR vs. CHAR£ºÃ÷È· MySQL ÖÐÊý¾ÝÀàÐͲî±ð
ÔÚ MySQL ÖУ¬VARCHAR ºÍ CHAR ¶¼ÊÇÓÃÓÚ´æ´¢±ä³¤µÄ×Ö·û´®Êý¾ÝÀàÐÍ¡£È»¶ø£¬Á½ÕßÖ®¼ä±£´æһЩҪº¦²î±ð£¬Õâ¿ÉÄÜ»áÓ°ÏìÊý¾Ý¿âÐÔÄܺÍÓ¦ÓóÌÐòµÄÓÐÓÃÐÔ¡£
Çø±ð£º
Ö÷ÒªÇø±ðÔÚÓÚ CHAR ÒÔÀο¿³¤¶È´æ´¢Êý¾Ý£¬¶ø VARCHAR ƾ֤ÏÖʵ×Ö·û´®³¤¶È´æ´¢Êý¾Ý¡£
Àο¿³¤¶È (CHAR)£º
×ÜÊÇÓÐÔ¤½ç˵µÄ³¤¶È£¨Ö¸¶¨½¨Éè±íʱ£©¡£
×ÝÈ»ÏÖʵÊý¾Ý½Ï¶Ì£¬ÈÔʹÓÃÌî³äÖµ£¨Í¨³£Îª¿Õ¸ñ£©Ìî³äµ½½ç˵µÄ³¤¶È¡£
Óŵ㣺¸ü¿ìµÄË÷Òý²éÕҺͽÏÁ¿²Ù×÷¡£
Èõµã£º´æ´¢¿Õ¼äÆÌÕÅ£¬ÌØÊâÊǵ±´æ´¢½Ï¶ÌµÄ×Ö·û´®Ê±¡£
¿É±ä³¤¶È (VARCHAR)£º
ƾ֤ÏÖʵ×Ö·û´®³¤¶È´æ´¢Êý¾Ý¡£
ûÓÐÔ¤½ç˵µÄ³¤¶ÈÏÞÖÆ£¨×î´ó³¤¶ÈΪ 65,535 ¸ö×Ö·û£©¡£
Óŵ㣺½ÚÔ¼´æ´¢¿Õ¼ä£¬ÌØÊâÊǵ±´æ´¢½Ï¶ÌµÄ×Ö·û´®Ê±¡£
Èõµã£ºË÷Òý²éÕҺͽÏÁ¿²Ù×÷ͨ³£½ÏÂý¡£
ÆäËû²î±ð£º
ĬÈϳ¤¶È£º VARCHAR µÄĬÈϳ¤¶ÈΪ 1£¬¶ø CHAR µÄĬÈϳ¤¶ÈΪ 0¡£
Ö´ÐÐÍýÏ룺 ÔÚijЩÇéÐÎÏ£¬ÀýÈçÅþÁ¬²Ù×÷£¬MySQL ÓÅ»¯Æ÷¿ÉÄÜ»áΪ CHAR ¶ø²»ÊÇ VARCHAR ½¨Éè¸üÓÐÓõÄÖ´ÐÐÍýÏë¡£
Ë÷Òý£º CHAR ͨ³£±È VARCHAR ¸üÊʺÏË÷Òý£¬ÓÉÓÚÆäÀο¿³¤¶ÈÔÊÐí¸ü¿ìµÄË÷Òý²éÕÒ¡£
Ñ¡ÔñºÏÊʵÄÊý¾ÝÀàÐÍ£º
ÔÚÑ¡Ôñ VARCHAR ºÍ CHAR ʱ£¬ÒÔÏÂ×¼ÔòÊÇÖÁ¹ØÖ÷ÒªµÄ£º
Êý¾Ý³¤¶È£º ÈôÊÇ×Ö·û´®³¤¶ÈÔ¤¼ÆÏà¶ÔÀο¿£¬ÔòӦʹÓà CHAR¡£ÈôÊdz¤¶È²î±ðºÜ´ó£¬ÔòӦʹÓà VARCHAR¡£
ÐÔÄÜ£º ¹ØÓÚ¾³£ÓÃÓÚË÷Òý»ò½ÏÁ¿²Ù×÷µÄ×ֶΣ¬CHAR ¿ÉÄÜÊǸüºÃµÄÑ¡Ôñ¡£
´æ´¢Ð§ÂÊ£º ¹ØÓÚ¾³£´æ´¢½Ï¶Ì×Ö·û´®µÄ×ֶΣ¬VARCHAR ¿ÉÒÔ½ÚÔ¼´ó×Ú´æ´¢¿Õ¼ä¡£
ͨ¹ýÏàʶ VARCHAR ºÍ CHAR Ö®¼äµÄ²î±ð£¬¿ª·¢Ö°Ô±¿ÉÒÔ×ö³öÃ÷ÖǵľöÒ飬ѡÔñ×îÊʺÏÆäÓ¦ÓóÌÐòºÍÊý¾Ý¿âÐÔÄÜÐèÇóµÄÊý¾ÝÀàÐÍ¡£
ÒÔÉϾÍÊÇmysqlÖÐvarcharºÍcharµÄÇø±ðµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡