database - Mysql Unique record 2 columns -


i making application inserts users mysql database.

i know can make column value unique, want combination of 2 columns in record unique.

for example:

id   firstname   lastname    creationdate -----------------------------------------  1   john        doe         (today) 

what want achieve can enter record :

 2, john, deo, (today) 

but cannot enter:

2, john, doe, (today) 

what sql statement can use make combination of multiple columns unique?

use below query

alter table persons add constraint pk_personid primary key (firstname,lastname) 

http://www.w3schools.com/sql/sql_primarykey.asp


Comments

Popular posts from this blog

ruby on rails - Permission denied @ sys_fail2 - (D:/RoR/projects/grp/public/uploads/ -

c++ - nodejs socket.io closes connection before upgrading to websocket -

python - PyQt: Label not showing correct number of length -