I have table mycar(made_by) column. Now I have two other BMW(bm_maker) and Audi(audi_maker). Let me explain the scenario, under mycar(made_by) I can have values from BMW(bm_maker) or Audi(audi_maker).

Therefore, I want to add foreign key references to both the tables BMW(bm_maker) and Audi(audi_maker).

  • 3
    Your data model is not good. You shouldn't be having a table per manufacturer – Philᵀᴹ Oct 27 '16 at 7:29
  • First, you cannot have two FK on the same column.
  • Second, it's totally bad design to have a table for each automaker.

What you should do is have one AUTO_MAKER table with the folowing columns:

maker_id (PK)

Such a table will have as many rows as automakers you decide to have in your database, one automaker for row.

Then, in the CAR table create a column maker_id with a FK to AUTOMAKER'S PK. Such a column could allow NULL in case you don't know the automaker at the moment of inserting a row in CAR. Or it could not allow NULL if you want to be strict, so forcing users to only insert cars with known and existing automakers (existing in the AUTO_MAKER table).

By the way, the question is RDBMS agnostic.

| improve this answer | |

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.