0

I am making an application which inserts users into a MySQL database.

I know you can make a column value unique, but I want a combination of 2 columns in a record to be unique.

For example:

id   firstname   lastname    creationdate
-----------------------------------------
 1   John        Doe         (today)

What I want to achieve is that I can enter a record like :

 2, John, Deo, (today)

but I cannot enter:

2, John, Doe, (today)

What SQL statement can I use to make a combination of multiple columns unique?

marc_s
  • 675,133
  • 158
  • 1,253
  • 1,388
JasperFennet
  • 51
  • 10
  • Possible duplicate of [How do I specify unique constraint for multiple columns in MySQL?](http://stackoverflow.com/questions/635937/how-do-i-specify-unique-constraint-for-multiple-columns-in-mysql) – Isaac Bennetch May 09 '16 at 16:29

1 Answers1

0

use the below query

ALTER TABLE Persons
ADD CONSTRAINT pk_PersonID PRIMARY KEY (FirstName,LastName)

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

Andrews B Anthony
  • 1,296
  • 7
  • 25