About Foreign Keys that is not a primary to other tables

Posted on

Question :

I’m clearly new into database implementation and I’m having doubts about my keys.

I have about 5 tables namely: User, Profile, Client, Stylist and also Posts sirs.

I have a certain foreign key named bioID which is located in Profile, Client and Stylist (It talks about a little of their biography.)

bioID is pointed to the Posts but I have already set PostID which is to contain regularity/uniformity for the Posts sirs

Is it okay for the bioID to be just a foreign key for all of the tables?

it is just “Posts” table sir. So the “Users” table contains the usernames and passwords as well as timestamps of when they are created. “Profile” contains a user information such as name, sex, age, occupation and etc. But there are 2 kinds of users so I split them into two tables which are “Client” and “Stylists”. The only thing that differs them is the “Stylists” would have a verification column as they need to verify that they are really stylists. “Posts” contains the post they make whenever a client needs a stylist or a stylists is open and available.

Users has “UserID” which is a foreign key to Table Profile. Profile has a foreign key “user_type” used to Table “Client” and “Stylist”. and both Client and Stylist table holds a bioID which is a foreign key to Table Bio(so that it will be organized w/ timestamps).

Answer :

A foreign key (FK) is just a constraint that limits the values in some column of a certain table to be present in another column in the other table.

That is all about so-called referential consistency of data and prevent you from adding/updating/deleting that can cause an emerging of orphaned data having no correspondence when it should have.

FK in fact should not be a PK or UK or any other kind of key for referred table but having referential correspondence means that you plan to JOIN to that table in some way. Joining by that column is the reason to create the index.

Leave a Reply

Your email address will not be published. Required fields are marked *