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

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -