mysqlÖи´ºÏÖ÷¼üÔõôÉèÖÃ
mysql ÖÐÉèÖø´ºÏÖ÷¼üµÄÒªÁìÓУº½¨Éè±íʱָ¶¨»òʹÓà alter table Óï¾ä£¬Æä×÷ÓÃÊÇΨһ±êʶÿһÐУ¬Ìá¸ßÅÌÎÊÐÔÄܺÍÊý¾ÝÍêÕûÐÔ¡£Óŵã°üÀ¨¿ìËÙ²éÕÒÐС¢Ç¿ÖÆΨһÐԺͿç¶à¸öÁмá³ÖΨһÐÔ£¬µ«ÈõµãÊÇÔöÌí´æ´¢¿ªÏúºÍÓ°ÏìÐÔÄÜ¡£
MySQL ÖÐÉèÖø´ºÏÖ÷¼ü
¸´ºÏÖ÷¼üÊÇÒ»¸ö°üÀ¨¶à¸öÁеÄΨһË÷Òý£¬ËüÓÃÓÚΨһ±êʶ±íÖеÄÿһÐС£Ëüͨ³£ÓÃÓÚ½¨Éè¸ü¾ßΨһÐÔµÄË÷Òý£¬ÒÔÌá¸ßÅÌÎÊÐÔÄܺÍÊý¾ÝµÄÍêÕûÐÔ¡£
ÔõÑùÉèÖø´ºÏÖ÷¼ü£º
½¨Éè±íʱָ¶¨£º
CREATE TABLE table_name ( column1 datatype, column2 datatype, PRIMARY KEY (column1, column2) );
µÇ¼ºó¸´ÖÆ
ʹÓà ALTER TABLE Óï¾ä£º
ALTER TABLE table_name ADD PRIMARY KEY (column1, column2);
µÇ¼ºó¸´ÖÆ
ʾÀý£º
½¨ÉèÒ»¸öÃûΪ customers µÄ±í£¬ÆäÖÐ first_name ºÍ last_name ÁÐ×é³É¸´ºÏÖ÷¼ü£º
CREATE TABLE customers ( customer_id INT NOT NULL AUTO_INCREMENT, first_name VARCHAR(255) NOT NULL, last_name VARCHAR(255) NOT NULL, PRIMARY KEY (first_name, last_name) );
µÇ¼ºó¸´ÖÆ
Óŵ㣺
Ìá¸ßÅÌÎÊÐÔÄÜ£¬ÓÉÓÚÖ÷¼üÓÃÓÚ¿ìËÙ²éÕÒÐС£
È·±£Êý¾ÝµÄÍêÕûÐÔ£¬ÓÉÓÚͳһ¶ÔÖµ²»¿ÉÓÃÓÚ¶àÐС£
ÔÊÐí¿ç¶à¸öÁÐÇ¿ÖÆΨһÐÔ¡£
¾ÖÏÞÐÔ£º
ÓÉÓÚÐèÒªÔÚ¶à¸öÁÐÉÏά»¤Ë÷Òý£¬Òò´Ë»áÔöÌí´æ´¢¿ªÏú¡£
ɾ³ý»ò¸üÐÂÖ÷¼üÁеÄÈκβ¿·Ö¶¼¿ÉÄÜ»áÓ°ÏìÐÔÄÜ£¬ÓÉÓÚÐèÒªÖØй¹½¨Ë÷Òý¡£
ÒÔÉϾÍÊÇmysqlÖи´ºÏÖ÷¼üÔõôÉèÖõÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡