Practice mode DBMS and SQL

Emp.dept_id is a foreign key to Dept(id) and is not declared NOT NULL. What happens when you insert an Emp row with dept_id set to NULL?

Correct answer B. The insert succeeds, because a NULL foreign key is not checked

Explanation

Referential integrity requires a foreign key value either to match an existing referenced key or to be NULL. A NULL foreign key means the relationship is unknown or absent, so the constraint is not violated and the insert succeeds. If every employee must belong to a department, add NOT NULL to dept_id as well. The DBMS never invents parent rows.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.