mysqlÖеÄkeyÊÇʲô
mysql ÖÐµÄ key ÊÇË÷Òý½á¹¹£¬ÓÃÓÚ¿ìËÙ²éÕҺͻá¼ûÊý¾Ý¡£Ëü´æ´¢ÁÐÖµºÍÐÐÖ¸Õ룬²¢Æ¾Ö¤ÁÐÖµ¿ìËÙ¶¨Î»Êý¾ÝÐУ¬Ìá¸ßÅÌÎÊÐÔÄÜ¡£mysql Ö§³Ö¶àÖÖ key ÀàÐÍ£¬°üÀ¨Ö÷¼ü¡¢Î¨Ò»¼ü¡¢Í¨Ë×Ë÷Òý¡¢È«ÎÄË÷ÒýºÍÍâ¼ü¡£
MySQL ÖÐµÄ Key
ʲôÊÇ Key£¿
ÔÚ MySQL Êý¾Ý¿âÖУ¬Key ÊÇÓÃÓÚ¿ìËÙ²éÕҺͻá¼ûÊý¾ÝµÄÒ»ÖÖË÷Òý½á¹¹¡£Ëü´æ´¢×ÅÊý¾Ý±íÖÐÒ»Áлò¶àÁеÄÖµ£¬ÒÔ¼°ÕâЩֵ¶ÔÓ¦µÄÐÐÖ¸Õë¡£
Key µÄÀàÐÍ
MySQL Ö§³Ö¶àÖÖÀàÐ굀 Key£¬Ã¿ÖÖÀàÐͶ¼ÓÐÆäÌض¨µÄÓÃ;ºÍÌØÕ÷£º
Ö÷¼ü (PRIMARY KEY)£ºÃ¿¸ö±íÖ»ÄÜÓÐÒ»¸öÖ÷¼ü£¬ËüÇ¿ÖÆÁÐֵΨһÇÒ·Ç¿Õ¡£
Ψһ¼ü (UNIQUE KEY)£º³ýÁËÖ÷¼üÖ®Í⣬ÿ¸ö±í»¹¿ÉÒÔÓжà¸öΨһ¼ü¡£Î¨Ò»¼üÖеÄÖµ±ØÐèΨһ£¬µ«ÔÊÐíΪ¿ÕÖµ¡£
ͨË×Ë÷Òý (INDEX)£ºÍ¨Ë×Ë÷Òý²»»áÇ¿ÖÆÁÐÖµµÄΨһÐÔ¡£ËüÖ»ÊÇÔÚÁÐÉϽ¨ÉèË÷Òý£¬¼ÓËÙ²éÕÒÊý¾ÝµÄËÙÂÊ¡£
È«ÎÄË÷Òý (FULLTEXT)£ºÈ«ÎÄË÷ÒýÓÃÓÚ¶ÔÎı¾×ֶξÙÐпìËÙËÑË÷£¬Ö§³Ö×ÔÈ»ÓïÑÔÅÌÎÊ¡£
Íâ¼ü (FOREIGN KEY)£ºÍâ¼üÓÃÓÚÔÚÁ½¸ö±íÖ®¼ä½¨Éè¹Øϵ£¬ËüÒýÓÃÁíÒ»¸ö±íµÄÖ÷¼ü»òΨһ¼ü¡£
Key µÄ×÷ÓÃ
Key µÄÖ÷Òª×÷ÓÃÊÇͨ¹ý¿ìËÙ²éÕÒÊý¾ÝÀ´Ìá¸ßÅÌÎÊÐÔÄÜ£º
Ë÷ÒýÔÊÐí MySQL Ö±½Ó¶¨Î»µ½Êý¾Ý±íµÄÌض¨ÐУ¬¶øÎÞÐèɨÃèÕû¸ö±í¡£Õâ¿ÉÒÔÏÔ×ÅïÔÌÅÌÎÊʱ¼ä¡£
Key »¹¿ÉÒÔ×ÊÖú MySQL ÓÅ»¯ÅÌÎÊÍýÏ룬ѡÔñ×îÓÐÓõÄÖ´ÐÐÕ½ÂÔ¡£
½¨Éè Key
¿ÉÒÔʹÓà CREATE INDEX Óï¾äΪÊý¾Ý±í½¨Éè Key£º
CREATE INDEX index_name ON table_name (column_name);
µÇ¼ºó¸´ÖÆ
ɾ³ý Key
¿ÉÒÔʹÓà DROP INDEX Óï¾äɾ³ý Key£º
DROP INDEX index_name ON table_name;
µÇ¼ºó¸´ÖÆ
ÒÔÉϾÍÊÇmysqlÖеÄkeyÊÇʲôµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡