mysqlÖÐcheckµÄ×÷ÓÃ
mysql ÖÐ check Ô¼Êø
MySQL ÖÐµÄ CHECK Ô¼ÊøÓÃÓÚÔÚ±íÖжÔÁлò±í´ïʽʩ¼Ó¸üÖØ´óµÄÏÞÖÆ£¬³ýÁËÊý¾ÝÀàÐÍºÍ NOT NULL Ô¼ÊøÖ®Íâ¡£
×÷ÓÃ
CHECK Ô¼ÊøÔÊÐíÊý¾Ý¿âÖÎÀíÔ±½ç˵Ìõ¼þ£¬ÒÔÈ·±£Áлò±í´ïʽµÄÖµÖª×ãÌض¨±ê×¼¡£ÕâÓÐÖúÓÚά»¤Êý¾ÝÍêÕûÐÔ£¬²¢±ÜÃâÒâÍâ»òÎÞЧµÄÊý¾Ý½øÈë±íÖС£
ʹÓ÷½·¨
CHECK Ô¼Êø¿ÉÒÔÔÚ½¨Éè±íʱÌí¼Ó£¬Ò²¿ÉÒÔÔÚÒÔºóʹÓà ALTER TABLE Óï¾äÌí¼Óµ½ÏÖÓбíÖС£ÆäÓï·¨ÈçÏ£º
CHECK (expression)
µÇ¼ºó¸´ÖÆ
ÆäÖÐ expression ÊDz¼¶û±í´ïʽ£¬ÆäЧ¹û±ØÐèΪ TRUE ²Å»ª²åÈë»ò¸üбíÖеÄÐС£ÀýÈ磬ÒÔÏ CHECK Ô¼ÊøÈ·±£ age ÁÐÖеÄÖµ´óÓÚ 0£º
CHECK (age > 0)
µÇ¼ºó¸´ÖÆ
Óŵã
ʹÓà CHECK Ô¼Êø¾ßÓÐÒÔÏÂÓŵ㣺
Ìá¸ßÊý¾ÝÍêÕûÐÔ£ºCHECK Ô¼ÊøÓÐÖúÓÚÈ·±£±íÖеÄÊý¾ÝÓÐÓÃÇÒ׼ȷ¡£
ÏÞÖÆÎÞЧÊäÈ룺ËüÃÇ¿ÉÒÔ±ÜÃâÓëÔ¼ÊøÌõ¼þ²»Æ¥ÅäµÄÎÞЧÊý¾Ý½øÈë±íÖС£
Ìṩ¸üºÃµÄÐÔÄÜ£ºÍ¨¹ýÔÚÊý¾Ý¿â¼¶±ðʵÑéÔ¼Êø£¬MySQL ¿ÉÒÔ×èÖ¹¶ÔÎÞЧÊý¾Ý¾ÙÐÐÌÚ¹óµÄÅÌÎʺ͸üвÙ×÷¡£
¼ò»¯Ó¦ÓóÌÐòÂß¼£ºCHECK Ô¼Êø¿ÉÒÔ½«Êý¾ÝÑéÖ¤Âß¼´ÓÓ¦ÓóÌÐòתÒƵ½Êý¾Ý¿â£¬´Ó¶ø¼ò»¯Ó¦ÓóÌÐò´úÂë¡£
×¢ÖØÊÂÏî
ʹÓà CHECK Ô¼Êøʱ£¬ÐèҪעÖØÒÔÏÂÊÂÏ
ÐÔÄÜÓ°Ï죺ʹÓÃÖØ´óµÄ»òÉæ¼°¶à¸öÁÐµÄ CHECK Ô¼Êø¿ÉÄÜ»áÓ°ÏìÊý¾Ý¿âÐÔÄÜ¡£
²»ÊÊÓÃÓÚÐéÄâÁУºCHECK Ô¼Êø²»¿ÉÓ¦ÓÃÓÚÐéÄâÁУ¨×ÝÈ»Óà AS ×Ӿ佨ÉèµÄÁУ©¡£
´¥·¢Æ÷Ìæ»»¼Æ»®£ºÔÚijЩÇéÐÎÏ£¬´¥·¢Æ÷¿ÉÒÔ×÷Ϊ CHECK Ô¼ÊøµÄÌæ»»¼Æ»®£¬Ìṩ¸üÎÞаµÄÔ¼ÊøÑ¡Ïî¡£
ÒÔÉϾÍÊÇmysqlÖÐcheckµÄ×÷ÓõÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡