Say I have a users table with uid, name, email, and password with a PRIMARY KEY on uid and a UNIQUE KEY on email.
Now I want to create a profiles table with uid, and other extended profile information. Should uid be a PRIMARY KEY or a FOREIGN KEY referencing uid from users in this case?
Ok thank you! Do I not want to force uniqueness of uid in profiles though? Is this worthwhile? Would it then be accomplished through a primary key or a unique key?
Ok thank you! Do I not want to force uniqueness of uid in profiles though? Is this worthwhile? Would it then be accomplished through a primary key or a unique key?
Decide if there is a one-to-one mapping between users and profiles table. Im guessing there might be, in that for each row in users, there is only one row in profiles?
If thats the case, then set profiles.userid to be PRIMARY KEY. This obviously forces uniqueness.
It can also be a FOREIGN KEY into the users table (which normally wouldnt, in itself, enforce uniqueness)