sqlÖеÄ×Ö·ûÀàÐÍ°üÀ¨ÄÄЩ
sql ÖеÄ×Ö·ûÀàÐÍ¿É·ÖΪµ¥×Ö½Ú£¨char¡¢varchar£©¡¢Ë«×Ö½Ú£¨nchar¡¢nvarchar£©ºÍ unicode£¨text¡¢ntext£©ÀàÐÍ¡£ÕâЩÀàÐÍƾ֤´æ´¢ÈÝÁ¿ºÍÖ§³ÖµÄ×Ö·û¼¯¾ÙÐзÖÀ࣬ÀýÈç ascii¡¢utf-8 ºÍ unicode¡£Ñ¡ÔñºÏÊʵÄ×Ö·ûÀàÐÍÈ¡¾öÓÚ´æ´¢µÄÎı¾Êý¾ÝµÄ³¤¶ÈºÍ×Ö·û¼¯ÒªÇ󣬲¢Ë¼Á¿Êý¾Ý¿âÌض¨µÄÏÞÖƺ͹¦Ð§¡£
SQL ÖеÄ×Ö·ûÀàÐÍ
SQL£¨½á¹¹»¯ÅÌÎÊÓïÑÔ£©ÖÐÌṩÁ˶àÖÖ×Ö·ûÀàÐÍ£¬ÓÃÓÚ´æ´¢ºÍ´¦ÀíÎı¾Êý¾Ý¡£ÕâЩÀàÐÍ°üÀ¨£º
×Ö·ûÀàÐÍ·ÖÀà
SQL ÖеÄ×Ö·ûÀàÐÍƾ֤Æä´æ´¢ÈÝÁ¿ºÍ×Ö·û¼¯Ö§³Ö¶ø·ÖÀࣺ
1. µ¥×Ö½Ú×Ö·ûÀàÐÍ
CHAR(n)£ºÀο¿³¤¶ÈµÄ×Ö·ûÀàÐÍ£¬ÆäÖÐ n Ö¸¶¨×Ö·û´®µÄ×î´ó³¤¶È£¨1 ÖÁ 255£©¡£
VARCHAR(n)£º¿É±ä³¤¶ÈµÄ×Ö·ûÀàÐÍ£¬ÆäÖÐ n Ö¸¶¨×Ö·û´®ÔÊÐíµÄ×î´ó³¤¶È£¨1 ÖÁ 65535£©¡£
2. Ë«×Ö½Ú×Ö·ûÀàÐÍ
NCHAR(n)£ºÀο¿³¤¶ÈµÄ×Ö·ûÀàÐÍ£¬ÓÃÓڴ洢˫×Ö½Ú×Ö·û¡£Óë CHAR ÀàËÆ£¬n Ö¸¶¨×Ö·û´®µÄ×î´ó³¤¶È£¨1 ÖÁ 4000£©¡£
NVARCHAR(n)£º¿É±ä³¤¶ÈµÄ×Ö·ûÀàÐÍ£¬ÓÃÓڴ洢˫×Ö½Ú×Ö·û¡£Óë VARCHAR ÀàËÆ£¬n Ö¸¶¨×Ö·û´®ÔÊÐíµÄ×î´ó³¤¶È£¨1 ÖÁ 1073741823£©¡£
3. Unicode ×Ö·ûÀàÐÍ
TEXT£º¿É´æ´¢´ó×ÚÎı¾Êý¾ÝµÄÀàÐÍ£¬×î´ó³¤¶ÈΪ 65535 ¸ö×Ö·û£¨MySQL£©»ò 2 GB£¨ÆäËûÊý¾Ý¿â£©¡£
NTEXT£ºÓë TEXT ÀàËÆ£¬µ«ÓÃÓڴ洢˫×Ö½Ú Unicode ×Ö·û£¬×î´ó³¤¶È½ÏС£¨MySQL Ϊ 16777216 ¸ö×Ö·û£©¡£
×Ö·û¼¯Ö§³Ö
SQL ×Ö·ûÀàÐÍ»¹Ö§³Ö¶àÖÖ×Ö·û¼¯£¬ÓÃÓÚ´¦Àí²î±ðÓïÑÔºÍ×Ö·û±àÂ룺
ASCII£ºÓÃÓÚÓ¢Óï×Ö·ûºÍ·ûºÅµÄ±ê×¼×Ö·û¼¯¡£
UTF-8£ºÒ»Öֿɱ䳤¶È±àÂëµÄ×Ö·û¼¯£¬ÓÃÓÚ´æ´¢´ó´ó¶¼ÏÖ´úÓïÑÔ¡£
Unicode£ºÒ»ÖÖͨÓÃ×Ö·û¼¯£¬º¸ÇÁËÌìÏÂÉÏÏÕЩËùÓÐÊéÃæÓïÑÔ¡£
Ñ¡Ôñ×Ö·ûÀàÐÍ
Ñ¡ÔñºÏÊʵÄ×Ö·ûÀàÐÍÈ¡¾öÓÚËù´æ´¢Îı¾Êý¾ÝµÄ³¤¶ÈºÍ×Ö·û¼¯ÒªÇó¡£¹ØÓÚ¶Ì×Ö·û´®£¬Ê¹Óà CHAR »ò VARCHAR ¾Í×ã¹»ÁË¡£ÈôÊÇÐèÒª´æ´¢´ó×ÚÎı¾»òË«×Ö½Ú×Ö·û£¬ÔòÐèҪʹÓà TEXT »ò NTEXT ÀàÐÍ¡£±ðµÄ£¬»¹ÐèҪ˼Á¿Êý¾Ý¿âÌض¨µÄÏÞÖƺ͹¦Ð§¡£
ÒÔÉϾÍÊÇsqlÖеÄ×Ö·ûÀàÐÍ°üÀ¨ÄÄЩµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡