1. 程式人生 > >mysql建立表多個欄位的唯一約束

mysql建立表多個欄位的唯一約束

mysql中有些表有時需要做一些欄位的唯一約束,當然你也可以在insert前判斷有無的方式來防止重複,如果不想額外增加程式碼來更靈活的實現一些欄位的唯一約束,mysql提供了兩種方式:

1.unique key  

alter table xx
add unique key no_account(no,collection_account)

2.unique index

alter table xxadd unique no_account_index(no,collection_account);