0

im doing a quite simple database in which i need to connect people as friends.

In my first column i have user_id and in the second one i have friend_id. What i want to achieve is to prevent a duplicate entry.

for example i want to have something like this:

user_id ; friend_id

1 ; 2

1 ; 3

1 ; 4

and so on

and prevent this:

1 ; 2

1 ; 3

1 ; 3

1 ; 4

1 ; 4

iv tried everything. If i set user_id as primary or unique, it wont allow me 2 entries with user_id = 1;

any help? thanks

4

1 回答 1

1

正如此答案所述,如果您仅查询,则复合主键(例如)(user_id, friend_id)将不允许您使用索引friend_id。您也可以UNIQUE(user_id, friend_id).

于 2012-09-04T14:45:41.937 回答