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?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.