Relationship versus foreign key

I have been asked to create a relationship between 2 tables. The 1st thing noticed is the column to use in the relationship is a primary key in both tables. Does this mean I should create a foreign key instead?

8replies Oldest first
  • Oldest first
  • Newest first
  • Active threads
  • Popular
  • The primary keys can remain the same.  You would just create a foreign key between the tables.  The main requirement for foreign keys is they map to a primary key in the destination table.

  • Yes. Please set it up as a Foreign Key - Primary Key. They are better than the relationships in terms of performance as well as query generation capabilities.

  • Sorry, I just realized that the desired column is the primary key in only one of the 2 tables. How does that change your replies?

  • As long as the foreign key is pointing to the primary key, that's fine.  For example, imagine you have an order table and customers table.  If the customer table has a primary key of customer_id and the order table has a customer_id column (not part of PK), then you can still create an FK from the order table to customer table on customer_id.

  • Thanks a lot!

  • In your example: the foreign key itself would be created in the ORDERS table, correct:

  • Correct.  Fact to dimension or many to one is the usual direction.

  • Thanks Bill!

Like Follow
  • Status Answered
  • 2 yrs agoLast active
  • 8Replies
  • 639Views
  • 3 Following