×ðÁú¿­Ê±¹ÙÍøµÇ¼

mysqlÖÐcheckµÄÓ÷¨

mysql check Ô¼ÊøÊÇÒ»ÖÖÊý¾Ý¿âÔ¼Êø£¬ÓÃÓÚÈ·±£Êý¾Ý±íÖеÄÁÐÖª×ãÖ¸¶¨µÄÌõ¼þ¡£ËüʹÓà alter table Óï¾ä½¨É裬Ó﷨Ϊ£ºalter table table_name add constraint constraint_name check (condition)¡£ÀûÒæ°üÀ¨Êý¾ÝÍêÕûÐÔ¡¢´úÂë¿É¶ÁÐÔºÍÐÔÄÜÓÅ»¯¡£ÐèҪעÖصÄÊÇ£¬check Ô¼ÊøÖ»ÔÚÊý¾Ý²åÈë»ò¸üÐÂʱ¼ì²éÊý¾Ý£¬²»ÊÊÓÃÓÚÏÖÓеÄÊý¾Ý¡£

MySQL CHECK Ô¼Êø

ʲôÊÇ CHECK Ô¼Êø£¿

CHECK Ô¼ÊøÊÇÒ»ÖÖÊý¾Ý¿âÔ¼Êø£¬ËüÓÃÓÚÈ·±£Êý¾Ý±íÖеÄÁÐÖª×ãÖ¸¶¨µÄÌõ¼þ¡£

ÔõÑùʹÓà CHECK Ô¼Êø£º

CHECK Ô¼Êø¿ÉÒÔʹÓÃÒÔÏÂÓï·¨½¨É裺

ALTER TABLE table_name ADD CONSTRAINT constraint_name CHECK (condition);

µÇ¼ºó¸´ÖÆ

ÆäÖУº

table_name ÊÇÒªÌí¼ÓÔ¼ÊøµÄÊý¾Ý±íÃû³Æ¡£

constraint_name ÊÇÔ¼ÊøµÄΨһÃû³Æ¡£

condition ÊÇÒª¼ì²éµÄÌõ¼þ£¬Ëü¿ÉÒÔÊÇÈκÎÓÐÓÃµÄ SQL ±í´ïʽ¡£

Ìõ¼þʾÀý£º

ÒÔÏÂÊÇһЩ CHECK Ô¼ÊøÌõ¼þʾÀý£º

salary > 0: È·±£ salary ÁеÄÖµ´óÓÚ 0¡£

age BETWEEN 18 AND 65: È·±£ age ÁеÄÖµ½éÓÚ 18 ºÍ 65 Ö®¼ä¡£

gender IN (‘M’, ‘F’): È·±£ gender ÁеÄֵΪ ‘M’ »ò ‘F’¡£

Óŵ㣺

ʹÓà CHECK Ô¼ÊøµÄÀûÒæ°üÀ¨£º

Êý¾ÝÍêÕûÐÔ£ºËü¿ÉÈ·±£²åÈëµ½Êý¾Ý±íÖеÄÊý¾ÝÖª×ãÖ¸¶¨µÄÌõ¼þ¡£

´úÂë¿É¶ÁÐÔ£ºËüÔÊÐíÔÚ½¨Éè±íʱָ¶¨Ìõ¼þ£¬´Ó¶øÌá¸ß´úÂëµÄ¿É¶ÁÐÔ¡£

ÐÔÄÜÓÅ»¯£ºÊý¾Ý¿â¿ÉÒÔʹÓà CHECK Ô¼ÊøÀ´¿ìËÙ¼ì²é²åÈëµÄÊý¾Ý£¬´Ó¶øÌá¸ßÐÔÄÜ¡£

×¢ÖØÊÂÏ

ÔÚʹÓà CHECK Ô¼Êøʱ£¬ÐèҪ˼Á¿ÒÔÏÂ×¢ÖØÊÂÏ

CHECK Ô¼ÊøÖ»ÔÚÊý¾Ý²åÈë»ò¸üÐÂʱ¼ì²éÊý¾Ý¡£

ÈôÊÇÎ¥·´ CHECK Ô¼Êø£¬½«Òý·¢¹ýʧ£¬×èÖ¹²åÈë»ò¸üвÙ×÷¡£

CHECK Ô¼Êø²»ÊÊÓÃÓÚÏÖÓеÄÊý¾Ý£¬ËüÖ»ÊÊÓÃÓÚÔÚ½¨ÉèÔ¼Êøºó²åÈëµÄÐÂÊý¾Ý¡£

ÒÔÉϾÍÊÇmysqlÖÐcheckµÄÓ÷¨µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí£¬°æȨÕùÒéÓë±¾Õ¾Î޹أ¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í×ðÁú¿­Ê±¹ÙÍøµÇ¼ÂËÓÍ»úÍø¹Ù·½Ì¬¶È£¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ£¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢£¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢£¬ÇëÄúÁ¬Ã¦ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼ʵʱÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎ壬9:30-18:30£¬½ÚãåÈÕÐÝÏ¢

QR code
ÍøÕ¾µØͼ