唯一鍵特點:
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;