Use app×
QUIZARD
QUIZARD
JEE MAIN 2026 Crash Course
NEET 2026 Crash Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
179 views
in Computer by (49.6k points)
closed by

Why foreign keys are allowed to have NULL values? Explain with an example.

1 Answer

+1 vote
by (51.9k points)
selected by
 
Best answer

Foreign keys are allowed to have NULL values because they are used to refer to a table from another table and it can be the case that some rows in the table might not have any relation to the other table in that case that row's foreign key field would be NULL meaning this row is not relating to the other table. 

Consider an employee and department tables,

Employee(Name, Id, DepartmentId)

Department(DepartmentId, DepartmentName)

Here, DepartmentId of Employee table is foreign key to Department table's DepartmentId, now consider a new employee joins the organization, we don't know what department he will be joining so we can have DepartmentId for that employee as NULL but for other employees it can be there. This NULL value shows that employee till now is not related to any department.

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...