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
Give the terms for each of the following:
(a) Collection of logically related records.
(b) DBMS creates a file that contains description about the data stored in the database.
(c) Attribute that can uniquely identify the tuples in a relation.
(d) Special value that is stored when actual data value is unknown for an attribute.
(e) An attribute which can uniquely identify tuples of the table but is not defined as primary key of the table.
(f) Software that is used to create, manipulate and maintain a relational database.
Differentiate between database state and database schema.
Differentiate between primary key and foreign key.
Differentiate between degree and cardinality of a relation.