balanv
balanv

Reputation: 10898

is it valid for a foreign key to be null?

is it valid for a foreign key to be null? i just created a table with foreign key relationship with another table. But i can insert values into the table without specifiying foreign key!

can the foreign key be null?

Upvotes: 0

Views: 124

Answers (1)

Oded
Oded

Reputation: 499392

Generally speaking, yes, it is valid.

It depends on what you are modelling.

If the entities you have does not have to link to the foreign key table entities (1 or none relationship), then allowing the foreign key column to be null is fine.

If that's not the case (and the relationship is always 1-to-1), then this shouldn't be allowed and the foreign key column definition should have NOT NULL.

Upvotes: 1

Related Questions