mysql 唯一鍵


唯一鍵特點:
1、唯一鍵在一張表中可以有多個。 2、唯一鍵允許字段數據為NULL,NULL可以有多個(NULL不參與比較) //一個表中允許存在多個唯一鍵,唯一鍵允許為空,在不為空的情況下,不允許重復 //設置一個字段為唯一鍵
mysql> alter table `table1` add unique ( `name_new`);
Query OK, 0 rows affected (0.02 sec)
Records: 0  Duplicates: 0  Warnings: 0
mysql> desc table1;
+------------+------------------+------+-----+---------+----------------+
| Field      | Type             | Null | Key | Default | Extra          |
+------------+------------------+------+-----+---------+----------------+
| name_new   | char(32)         | YES  | UNI | NULL    |                |
| transactor | varchar(10)      | NO   |     | NULL    |                |
| pid        | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
+------------+------------------+------+-----+---------+----------------+
3 rows in set (0.00 sec)


//刪除唯一鍵(該字段依然存在)
alter table table1 drop index name_new;

 

 

 


免責聲明!

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



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