mysqlÖÐÖ÷¼üÔ¼ÊøÔõôд
mysqlÖеÄÖ÷¼üÔ¼ÊøÊÇÒ»ÖÖΨһԼÊø£¬ÓÃÓÚÃ÷È·½ç˵±íÖÐÿÐеÄΨһ±êʶ·û¡£¿ÉÒÔͨ¹ýʹÓÃprimary keyÒªº¦×Ö»òÔÚ½¨Éè±íʱָ¶¨À´½¨ÉèÖ÷¼üÔ¼Êø¡£Ö÷¼ü¿ÉÒÔÊǵ¥Áлò¸´ºÏÁУ¨Óɶà¸öÁÐ×é³É£©£¬»¹Ö§³Ö×Ô¶¯µÝÔöÖ÷¼ü£¬»áÔÚ²åÈëÐÂÐÐʱ×Ô¶¯ÌìÉúΨһֵ¡£Ö÷¼üÔ¼ÊøÈ·±£ÁËÊý¾ÝµÄÍêÕûÐÔºÍ׼ȷÐÔ£¬ÓÉÓÚÿһÐж¼¾ßÓÐΨһµÄÖµ¡£
MySQL ÖеÄÖ÷¼üÔ¼Êø
ʲôÊÇÖ÷¼üÔ¼Êø£¿
Ö÷¼üÔ¼ÊøÊÇÓÃÓÚΨһ±êʶ±íÖÐÿÐеÄÊý¾ÝµÄÒ»ÖÖΨһԼÊø¡£ËüÇ¿ÖƱíÖеÄÿһÐж¼¾ßÓÐΨһµÄÖµ£¬´Ó¶øÈ·±£Êý¾ÝµÄÍêÕûÐÔºÍ׼ȷÐÔ¡£
ÔõÑù½¨ÉèÖ÷¼üÔ¼Êø£¿
ÔÚ MySQL ÖУ¬Ê¹Óà PRIMARY KEY Òªº¦×Ö½¨ÉèÖ÷¼üÔ¼Êø¡£Óï·¨ÈçÏ£º
CREATE TABLE table_name ( column_name PRIMARY KEY );
µÇ¼ºó¸´ÖÆ
»òÕߣ¬Äú¿ÉÒÔÔÚ½¨Éè±íʱָ¶¨Ö÷¼üÔ¼Êø£º
CREATE TABLE table_name ( column_name1 INT NOT NULL, column_name2 VARCHAR(255) NOT NULL, PRIMARY KEY (column_name1, column_name2) );
µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ
¸´ºÏÖ÷¼ü
¸´ºÏÖ÷¼üÓÉÁ½¸ö»ò¶à¸öÁÐ×é³É£¬ËüÃÇÅäºÏÐγɱíµÄΨһ±êʶ·û¡£Óï·¨Óëµ¥ÁÐÖ÷¼üÀàËÆ£º
CREATE TABLE table_name ( column_name1 INT NOT NULL, column_name2 VARCHAR(255) NOT NULL, PRIMARY KEY (column_name1, column_name2) );
µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ
×Ô¶¯µÝÔöÖ÷¼ü
MySQL Ö§³Ö×Ô¶¯µÝÔöÖ÷¼ü£¬Ëü»áÔÚ²åÈëÐÂÐÐʱ×Ô¶¯ÎªÃ¿¸öÐÂÐÐÌìÉúÒ»¸öΨһֵ¡£Òª½¨Éè×Ô¶¯µÝÔöÖ÷¼ü£¬ÇëʹÓà AUTO_INCREMENT Òªº¦×Ö£º
CREATE TABLE table_name ( id INT NOT NULL AUTO_INCREMENT, column_name1 VARCHAR(255) NOT NULL, PRIMARY KEY (id) );
µÇ¼ºó¸´ÖÆ
×¢ÖØÊÂÏî
Ö÷¼üÁбØÐè¾ßÓÐΨһֵ¡£
Ö÷¼üÁв»¿ÉΪ NULL¡£
Ö÷¼üÔ¼Êø¿ÉÒÔÏÔʽ»òÒþʽ½¨Éè¡£
ÈôÊÇûÓÐÖ¸¶¨Ö÷¼üÔ¼Êø£¬MySQL »á×Ô¶¯Ñ¡Ôñ±íÖеĵÚÒ»¸ö·Ç¿ÕÁÐ×÷ΪÒþʽÖ÷¼ü¡£
ÒÔÉϾÍÊÇmysqlÖÐÖ÷¼üÔ¼ÊøÔõôдµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡