Skip to content
Advertisement

Simple database with 3 tables and “no matching unique or primary key for this column”

I have three tables, two are created independently, and the third one is created to include some inputs from the first two. First two tables have no problems, however, when I try to create the third one, I get an error:

The thing is, I created the third table by copy/pasting the column names/definitions right from the first two tables, yet I still get this ridiculous error message. Now I wonder if the order of the columns and the especially the order of constrains is important.

The tables:

  1. comm_Customers
  1. comm_Items
  1. comm_Orders which gives the error

Advertisement

Answer

The references to non-primary key columns of customers and items do raise the error.

Bottom-line, you should not be duplicating the information from the referential tables. A single foreign key is sufficient.

So:

Then, whenever you need to recover an information from a referential table, you join it using the foreign key. Say you want the phone of a customer:

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement