KnowledgeBoat Logo
|
LoginJOIN NOW

Computer Science

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

Relational Database

4 Likes

Answer

A null value can be entered in a foreign key, indicating that the records are not related. In certain situations, a foreign key may accept a NULL value if it's not a part of the primary key of the foreign table.

For example, consider an Orders table in a database. Each order may or may not be associated with a customer. If an order is placed by a guest or a new customer who hasn't been added to the system yet, the CustomerID foreign key in the Orders table can be NULL to indicate that there is no associated customer record for that order.

Answered By

3 Likes


Related Questions