Mysql中的primary key 與auto_increment


mysql> create table cc(id int auto_increment);
ERROR 1075 (42000): Incorrect table definition; there can be only one auto column and it must be def
ined as a key
mysql> create table cc(id int auto_increment primary key);
Query OK, 0 rows affected (0.03 sec)

mysql> desc cc;
+-------+---------+------+-----+---------+----------------+
| Field | Type    | Null | Key | Default | Extra          |
+-------+---------+------+-----+---------+----------------+
| id    | int(11) | NO   | PRI | NULL    | auto_increment |
+-------+---------+------+-----+---------+----------------+
1 row in set (0.01 sec)

mysql>

mysql> create table abc(id int primary key);
Query OK, 0 rows affected (0.04 sec)

mysql>

 

注意:

自動編號Auto_INCREMENT必須與主鍵PRIMARY KEY組合使用

primary key可以獨自使用

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM