mysqlÖÐÖ÷¼üÊÇÄĸöµ¥´Ê
mysqlÖУ¬Ö÷¼üÊÇΨһ±êʶ±íÖÐÿÌõ¼Í¼µÄÁлòÁÐ×飬¾ßÓÐΨһÐÔ¡¢·Ç¿ÕÐÔ¡¢Ç¿ÖÆÐÔµÈÌص㣬ÓÃÓÚÈ·±£Êý¾ÝÍêÕûÐÔ¡¢¿ìËÙ²éÕÒÊý¾ÝºÍ½¨ÉèÍâ¼ü¹Øϵ¡£¿ÉÒÔÕâÑùÉèÖÃÖ÷¼ü£ºalter table ±íÃû add primary key (ÁÐÃû)¡£
MySQL ÖеÄÖ÷¼ü
MySQL ÖУ¬Ö÷¼ü£¨Primary Key£©ÊÇÒ»¸öÊý¾Ý¿â±íÖÐΨһ±êʶÿÌõ¼Í¼µÄÁлòÒ»×éÁС£
ÌصãºÍ×÷Óãº
ΨһÐÔ£ºÖ÷¼üÖеÄÖµ±ØÐèÊÇΨһµÄ£¬¼´±íÖÐûÓÐÁ½Ìõ¼Í¼¾ßÓÐÏàͬµÄÖ÷¼üÖµ¡£
·Ç¿ÕÐÔ£ºÖ÷¼üͨ³£ÊDz»ÔÊÐíΪ NULL ÖµµÄ£¬ÒÔÈ·±£¼Í¼µÄ¿Éʶ±ðÐÔ¡£
Ç¿ÖÆÐÔ£º´ó´ó¶¼Êý¾Ý¿âÖÎÀíϵͳ£¨°üÀ¨ MySQL£©Ç¿ÖÆÔÚ±í½¨Éèʱ½ç˵Ö÷¼ü¡£
˞񾣼
È·±£Êý¾ÝÍêÕûÐÔ£ºÖ÷¼üÓÐÖúÓÚ±ÜÃâÖظ´¼Í¼µÄ²åÈ룬´Ó¶ø¼á³ÖÊý¾ÝµÄ׼ȷÐÔ¡£
¿ìËÙ²éÕÒÊý¾Ý£ºÊý¾Ý¿âʹÓÃÖ÷¼ü×÷ΪË÷Òý£¬¿ÉÒÔ¿ìËÙ¸ßЧµØ²éÕҼͼ¡£
Íâ¼ü¹Øϵ£ºÖ÷¼ü¿É×÷ΪÆäËû±íÖÐÍâ¼üµÄ²ÎÕÕ¹¤¾ß£¬ÓÃÓÚ½¨ÉèÊý¾ÝÖ®¼äµÄ¹Øϵ¡£
ÔõÑùÉèÖÃÖ÷¼ü£º
ÔÚ MySQL ÖУ¬Ê¹Óà PRIMARY KEY Ô¼Êø½ç˵Ö÷¼ü¡£Óï·¨ÈçÏ£º
ALTER TABLE table_name ADD PRIMARY KEY (column_name);
µÇ¼ºó¸´ÖÆ
ÀýÈ磺
ALTER TABLE customers ADD PRIMARY KEY (customer_id);
µÇ¼ºó¸´ÖÆ
Õ⽫Ϊ customers ±íÖÐµÄ customer_id ÁÐÉèÖÃÖ÷¼üÔ¼Êø¡£
ÒÔÉϾÍÊÇmysqlÖÐÖ÷¼üÊÇÄĸöµ¥´ÊµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡