Is it better to use foreign keys in tables or can the same results be achieved with joins?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Foreign keys are just constraints to enforce referential integrity. You will still need to use JOINs to build your queries.
Foreign keys guarantee that a row in a table
order_detailswith a fieldorder_idreferencing anorderstable will never have anorder_idvalue that doesn’t exist in theorderstable. Foreign keys aren’t required to have a working relational database (in fact MySQL’s default storage engine doesn’t support FKs), but they are definitely essential to avoid broken relationships and orphan rows (ie. referential integrity).