Is it possible to make a row in a database table unique? If so how? I know you can make a field unique so for example ‘John’ could not appear twice in a name field. But what if I have something like:
name: John
id: 1
foreign_key: 1
name: John
id: 2
foreign_key: 1
In this instance it would be fine as they are the same but different.
Where as this would be prevented:
name: John
id: 1
foreign_key: 1
name: John
id: 1
foreign_key: 1
It’s difficult to demonstrate as the obvious answer would be to make the foreign_key unique but in my case it’s a many to many relationship so the ID or foreign key could appear many many times but shouldn’t ever have the same data in all the columns.
I.e this should work:
id: 1
fKey: 2
afKey: 3
id: 1
fKey: 3
afKey: 3
BUT not when fKey and afKey match in two rows like:
id: 1
fKey: 2
afKey: 3
id: 1
fKey: 2
afKey: 3
To make the row unique you could make all 3 columns a composite primary key.
http://dev.mysql.com/doc/refman/5.0/en/multiple-column-indexes.html