-2

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).

  • 3
    I suggest you edit the question and add the CREATE TABLE statements for all the tables. it's not very clear what the design is and how the FKs are set up. – ypercubeᵀᴹ Oct 4 '18 at 9:12
  • 1
    @DenscottieMichaelCerna It looks like you might find of help this Q & A. Of course, you first have to establish some analogies between (a) the scenario dealt with there and (b) the one you describe. – MDCCL Oct 5 '18 at 21:21
0

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.

  • What you have defined is a foreign key constraint. Foreign keys can exist even if the constraint is not declared. – Walter Mitty Oct 8 '18 at 12:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.