mysqlÖÐuniqueµÄ×÷ÓÃ
mysql ÖÐµÄ unique Òªº¦×Ö½¨ÉèΨһË÷Òý£¬Ç¿ÖƱíÖÐÌض¨ÁлòÁÐ×éµÄÖµ±ØÐèΨһ£¬±ÜÃâÖظ´£¬²¢Ìá¸ßÅÌÎÊËÙÂÊ¡¢×èÖ¹²åÈëÖظ´Êý¾ÝºÍÓÅ»¯Êý¾Ý´æ´¢¡£
MySQL ÖÐ UNIQUE Òªº¦×ÖµÄ×÷ÓÃ
UNIQUE Òªº¦×ÖÓÃÓÚÔÚ MySQL ±íÖн¨ÉèΨһË÷Òý¡£ËüÇ¿ÖƱíÖÐijһÁлòÒ»×éÁеÄÖµ±ØÐèΨһ£¬²»¿ÉÖظ´¡£
×÷ÓÃ
°ü¹ÜÊý¾ÝÍêÕûÐÔ£ºUNIQUE Ë÷Òý¿É±ÜÃâͳһÁлòÁÐ×éÖзºÆðÖظ´Öµ£¬È·±£Êý¾ÝµÄ׼ȷÐÔ¡£
¼ÓËÙÅÌÎÊËÙÂÊ£º¹ØÓÚ°üÀ¨Î¨Ò»Ë÷ÒýµÄÁУ¬MySQL ¿ÉÒÔʹÓÃË÷Òý²éÕÒ£¬¶ø²»ÊÇɨÃèÕû¸ö±í£¬´Ó¶ø´ó´óÌá¸ßÅÌÎÊЧÂÊ¡£
×èÖ¹²åÈëÖظ´Êý¾Ý£ºµ±ÊµÑé²åÈëÖظ´ÖµÊ±£¬MySQL »á·µ»Ø¹ýʧ»ò³åÍ»£¬±ÜÃâÊý¾ÝÖظ´¡£
ÓÅ»¯Êý¾Ý´æ´¢£ºUNIQUE Ë÷ÒýÓÐÖúÓÚÏû³ýÈßÓàÊý¾Ý£¬ÓÅ»¯Êý¾Ý´æ´¢¿Õ¼ä¡£
ʹÓÃ
Òª½¨Éè UNIQUE Ë÷Òý£¬¿ÉÒÔÔÚ½¨Éè±í»òÐ޸ıíʱʹÓÃÒÔÏÂÓï·¨£º
CREATE TABLE table_name ( column_name1 UNIQUE, column_name2 UNIQUE, ... );
µÇ¼ºó¸´ÖÆ
»ò
ALTER TABLE table_name ADD UNIQUE (column_name1, column_name2, ...);
µÇ¼ºó¸´ÖÆ
×¢ÖØÊÂÏî
UNIQUE Ë÷Òý½öÔÊÐíÒ»¸ö¿ÕÖµ¡£
ÈôÊDZíÖÐÒѾ±£´æÖظ´Öµ£¬ÐèÒªÏÈɾ³ýÖظ´Öµ²Å»ª½¨Éè UNIQUE Ë÷Òý¡£
UNIQUE Ë÷ÒýÓë PRIMARY KEY Ë÷ÒýÀàËÆ£¬µ« PRIMARY KEY Ë÷Òý»¹Ç¿ÖÆÁÐÖµ²»Îª NULL¡£
¿ÉÒÔʹÓà IGNORE DUPLICATE KEYS Ñ¡ÏîÇ¿ÖÆ MySQL ºöÂÔÖظ´Öµ£¬µ«ÕâÑù»á½µµÍÊý¾ÝÍêÕûÐÔ¡£
ÒÔÉϾÍÊÇmysqlÖÐuniqueµÄ×÷ÓõÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡