mysqlÖÐÖ÷¼ü¿ÉÒÔΪ¿ÕÂð
mysqlÖеÄÖ÷¼ü²»¿ÉΪ¿Õ£¬ÓÉÓÚÕâ»áÎ¥·´Î¨Ò»ÐÔÔ¼Êø£¬Ó°ÏìÊý¾ÝÍêÕûÐÔ£¬²¢½µµÍÅÌÎÊÐÔÄÜ¡£Î¨Ò»ÔÊÐíÖ÷¼üÖаüÀ¨nullÖµµÄÇéÐÎÊÇ×Ô¶¯µÝÔöÁкÍ×éºÏÖ÷¼üÖÐijЩÁÐΪ¿Õ¡£
MySQL ÖÐÖ÷¼ü¿ÉÒÔΪ¿ÕÂð£¿
»Ø¸²£º·ñ£¬MySQL ÖеÄÖ÷¼ü²»¿ÉΪ¿Õ¡£
ÏêϸڹÊÍ£º
ÔÚ MySQL ÖУ¬Ö÷¼üÊÇÓÃÀ´Î¨Ò»±êʶ±íÖÐÿÌõ¼Í¼µÄÌØÊâÁС£Ö÷¼üÖµ±ØÐèÊǷǿյģ¬ÕâÒâζ×ÅËü²»¿É°üÀ¨ NULL Öµ¡£ÕâÊÇÓÉÓÚ£º
È·±£Êý¾ÝÍêÕûÐÔ£ºÈôÊÇÖ÷¼üÔÊÐíΪ¿Õ£¬Ôò¿ÉÄܻᵼÖ±íÖзºÆðÖظ´¼Í¼¡£ÕâÊÇÓÉÓÚÁ½¸ö²î±ðµÄ¼Í¼¿ÉÒÔ¾ßÓÐÏàͬµÄÖ÷¼ü£¬´Ó¶øÎ¥·´ÁËÖ÷¼üµÄΨһÐÔÔ¼Êø¡£
ÓÅ»¯ÅÌÎÊÐÔÄÜ£ºMySQL ʹÓÃÖ÷¼üÀ´¿ìËÙ¼ìË÷Êý¾Ý¡£ÈôÊÇÖ÷¼ü¿ÉÒÔΪ¿Õ£¬ÔòÊý¾Ý¿â½«ÎÞ·¨ÓÐÓõØʹÓÃË÷ÒýÀ´ÓÅ»¯ÅÌÎÊ£¬Õ⽫µ¼ÖÂÅÌÎÊÐÔÄÜϽµ¡£
˵Ã÷£º
ÔÚ MySQL ÖУ¬Äú¿ÉÒÔͨ¹ýÉèÖà NOT NULL Ô¼ÊøÀ´Ç¿ÖÆÖ÷¼üÁÐΪ·Ç¿Õ¡£ÀýÈ磺
CREATE TABLE my_table ( id INT NOT NULL PRIMARY KEY, name VARCHAR(255) );
µÇ¼ºó¸´ÖÆ
ÆÆÀýÇéÐΣº
ÔÚijЩÇéÐÎÏ£¬MySQL ÔÊÐíÔÚijЩÁÐÖÐʹÓà NULL Öµ×÷ΪÖ÷¼ü¡£ÕâЩÆÆÀý°üÀ¨£º
×Ô¶¯µÝÔöÁУºMySQL ¿ÉÒÔ½« AUTO_INCREMENT ÁÐÓÃ×÷Ö÷¼ü£¬×ÝÈ»Ëü°üÀ¨ NULL Öµ¡£ÕâÊÇÓÉÓÚ MySQL ÔÚ²åÈëмͼʱ»á×Ô¶¯·ÖÅÉΨһֵ¡£
×éºÏÖ÷¼ü£ºMySQL ÔÊÐíÔÚ×éºÏÖ÷¼üÖÐʹÓà NULL Öµ£¬Ö»ÒªÖ÷¼üÖеÄÆäËûÁаüÀ¨·Ç¿ÕÖµ¡£ÀýÈ磬ÈôÊÇ (id1, id2) ÊÇÒ»¸ö×éºÏÖ÷¼ü£¬Ôò id1 ¿ÉÒÔΪ¿Õ£¬Ö»Òª id2 ¾ßÓзǿÕÖµ¡£
È»¶ø£¬ÕâЩÆÆÀýÇéÐβ»ÊÊÓÃÓÚͨË×µÄÖ÷¼üÁС£ÔÚ´ó´ó¶¼ÇéÐÎÏ£¬MySQL ÖеÄÖ÷¼ü±ØÐèÊǷǿյġ£
ÒÔÉϾÍÊÇmysqlÖÐÖ÷¼ü¿ÉÒÔΪ¿ÕÂðµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡