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

wireshark - USB mapping with python -

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

Deploying Qt Application on Android is really slow? -