mysqlÖÐÖ÷¼üµÄÒªº¦×ÖÊÇʲô
ÔÚ mysql ÖУ¬Ê¹Óà primary key Òªº¦×ÖÖ¸¶¨Ö÷¼ü£¬Ö÷¼üÊÇΨһ±êʶÿÐмͼµÄ×ֶλò×Ö¶Î×éºÏ£¬¾ßÓÐΨһÐÔ£¨Ã¿ÐÐÖ÷¼üÖµ²î±ð£©ºÍ·Ç¿Õ£¨Ö÷¼üÖµ²»Îª null£©ÌØÕ÷¡£±ðµÄ£¬Ê¹ÓÃÒÔÏÂÓï·¨½ç˵Ö÷¼ü£ºcreate table table_name ( column_name1 data_type primary key, … )¡£
MySQL ÖÐÖ÷¼üµÄÒªº¦×Ö
ÔÚ MySQL ÖУ¬ÓÃÓÚÖ¸¶¨Ö÷¼üµÄÒªº¦×ÖÊÇ PRIMARY KEY¡£
Ö÷¼üµÄ½ç˵
Ö÷¼üÊÇÊý¾Ý¿â±íÖÐΨһ±êʶÿÐмͼµÄ×ֶλò×Ö¶Î×éºÏ¡£Ëü¾ßÓÐÒÔÏÂÌØÕ÷£º
ΨһÐÔ£º¹ØÓÚ¸ø¶¨±íÖеÄËùÓÐÐУ¬Ö÷¼üÖµ¶¼ÊÇΨһµÄ¡£
·Ç¿Õ£ºÖ÷¼ü²»¿ÉΪ NULL Öµ¡£
ʹÓà PRIMARY KEY Òªº¦×Ö
Òª½«Ò»¸ö»ò¶à¸ö×Ö¶ÎÖ¸¶¨ÎªÖ÷¼ü£¬ÇëÔÚ½¨Éè±íʱʹÓà PRIMARY KEY Òªº¦×Ö£¬ÈçÏÂËùʾ£º
CREATE TABLE table_name ( column_name1 DATA_TYPE PRIMARY KEY, column_name2 DATA_TYPE, ... );
µÇ¼ºó¸´ÖÆ
ÆäÖУº
table_name ÊDZíµÄÃû³Æ¡£
column_name1 ÊÇÖ÷¼ü×ֶεÄÃû³Æ¡£
DATA_TYPE Ö¸¶¨×ֶεÄÊý¾ÝÀàÐÍ¡£
ʾÀý
ÒÔÏÂʾÀý½¨ÉèÒ»¸öÃûΪ customers µÄ±í£¬ÆäÖÐ customer_id ÊÇÖ÷¼ü£º
CREATE TABLE customers ( customer_id INT PRIMARY KEY, name VARCHAR(255), email VARCHAR(255) );
µÇ¼ºó¸´ÖÆ
ÔÚÉÏÊöʾÀýÖУ¬customer_id ×Ö¶ÎÊÇΨһµÄÇҷǿյģ¬ÕâÒâζ×űíÖÐûÓÐÁ½ÐоßÓÐÏàͬµÄ customer_id Öµ£¬²¢ÇÒ customer_id ÖµÓÀÔ¶²»Îª NULL¡£
ÒÔÉϾÍÊÇmysqlÖÐÖ÷¼üµÄÒªº¦×ÖÊÇʲôµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡