0

So lets say there's 3 tables, two tables with questions in them and 1 marking table, would it be suitable for a foreign key to be null at times?

So for example:

Question Table A (Questions from a source (Sources defined using another table)) Question Table B (Custom made questions (Sources defined using words))

Marking Table

When a question from Question Table A needs to be added to the Marking Table, would it be suitable to leave the foreign key field for Table B null as a question has already been selected from Table A?

Is there any way of making this more simple? I believe having the data in this arrangement makes it suitable.

Thahleel al-Aleem
  • 711
  • 2
  • 10
  • 20

1 Answers1

1

I think you may define a base table for Table-A and Table-B called Question, that will contain shared properties of questions.
Having Foreign key of Question table in Marking table will solve the problem. enter image description here

Mohsen Heydari
  • 7,256
  • 4
  • 31
  • 46
  • Is this needed for a database situation that is correct to 3NF? How would you go about modelling Zero or One relationships in SQL? – Thahleel al-Aleem Dec 26 '13 at 19:58
  • Optional one-to-one relationships managed with NULLs in the FK column is a sample of zero-or-one, see [Class Table Inheritance](http://stackoverflow.com/questions/3579079/how-can-you-represent-inheritance-in-a-database/3579462#3579462) for more information – Mohsen Heydari Dec 26 '13 at 21:06