Home:ALL Converter>which one is better composite pk or using natural keys in blacklist design

which one is better composite pk or using natural keys in blacklist design

Ask Time:2012-12-01T02:13:58         Author:HiDd3N

Json Formatter

i am going to design my blacklist and favorite in php list which user can blacklist and favorite other persons and now i just want to know is it better to design like this

+-----+------+------------+
| uid(pk) | name | family |
+-----+------+------------+

and another table like this which is composite primary key

+-----+------+------------------------+
| uid(pk) | blacklisted_person_id(pk) |
+-----+------+------------------------+

or desgin with primary key and foreign key in it, which i dont know how to design in this case that user cant blacklist himself or blacklist some person 2 times.if someonce can describe it a little ill be grateful. thanks in advance

Author:HiDd3N,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/13650807/which-one-is-better-composite-pk-or-using-natural-keys-in-blacklist-design
Ray :

Your solution is good, but I'd recommend just calling your PK in your user table just id not uid and then in your mapping blacklist table refer to it as user_id (if user is the name of the user table) and blacklisted_user_id. That way there is no ambiguity to what table these individual columns are foreign keys to. \n\nThe reason it's a good solution is that it will prevent duplicates from being entered without having to create an additional unique composite key.",
2012-11-30T18:16:56
yy