| Lesson 12 | Mandatory and Optional Participation |
| Objective | Describe mandatory participation and enforce a required parent reference without confusing it with a parent's minimum number of children. |
Mandatory participation means that each instance of an entity must take part in a particular relationship. Its minimum participation is one. Optional participation allows zero related instances. These rules apply separately in each direction and come from the business requirements.
For example, every order must belong to a customer, but a customer may register before placing an order. Orders participate mandatorily in this relationship; customers participate optionally. The same relationship can therefore be mandatory from one viewpoint and optional from the other.
Ask two questions for each entity: Must a related instance exist? and How many can exist? Mandatory or optional describes the minimum; one or many describes the maximum.
| Starting from | Related instances | Minimum | Maximum |
|---|---|---|---|
| One order | Its customer | 1 | 1 |
| One customer | Their orders | 0 | Many |
In the diagram, 1 near Customers means one customer per order. 0..many near Orders means zero or many orders per customer. In Crow's Foot notation, read the complete minimum/maximum symbol pair: a circle indicates zero, a bar indicates one, and the crow's foot indicates many. A single bar in isolation does not describe both limits.
A customer may place zero or many orders. Every order belongs to exactly one customer.
An order needs a matching customer, not merely some row somewhere in Customers. If an order references CustomerID 999, the presence of customer 101 does not satisfy the rule.
CREATE TABLE Customers (
CustomerID INT NOT NULL PRIMARY KEY,
CustomerName VARCHAR(100) NOT NULL
);
CREATE TABLE Orders (
OrderID INT NOT NULL PRIMARY KEY,
CustomerID INT NOT NULL,
OrderDate DATE NOT NULL,
CONSTRAINT fk_orders_customer
FOREIGN KEY (CustomerID) REFERENCES Customers(CustomerID)
);
NOT NULL alone accepts a nonexistent identifier. A nullable foreign key alone permits an absent reference. Together, these constraints enforce the stated required-parent rule when constraint enforcement is enabled.
INSERT INTO Customers (CustomerID, CustomerName) VALUES
(101, 'Ava'),
(102, 'Ben');
INSERT INTO Orders (OrderID, CustomerID, OrderDate) VALUES
(5001, 101, '2026-10-01'),
(5002, 101, '2026-10-02');
Both orders are valid. Ben's customer row is also valid even though no order references it. In a practice database, test these statements separately; each is expected to fail:
-- Rejected: customer 999 does not exist.
INSERT INTO Orders (OrderID, CustomerID, OrderDate)
VALUES (5003, 999, '2026-10-03');
-- Rejected: the required customer reference is missing.
INSERT INTO Orders (OrderID, CustomerID, OrderDate)
VALUES (5004, NULL, '2026-10-03');
The examples assume ordinary immediate constraint checking: insert the parent before inserting its child. Some engines support explicitly deferred foreign keys, which can permit a different statement order within a transaction while still requiring a valid relationship when the constraint is checked. The enduring rule is a matching parent at validation time.
The example requests no cascade. With the foreign key enforced, deleting Ava while her orders remain is rejected. Deleting Ben, who has no orders, is allowed. Deleting an order does not delete its customer.
Use a restrictive policy when orders must be retained with their customer reference. Consider deactivation or an appropriate retention design rather than deleting required parent records. ON DELETE CASCADE deletes dependent orders when the customer is deleted; use it only if that is the intended business policy. SET NULL conflicts with this NOT NULL relationship.
Database engines differ in support and timing for RESTRICT and NO ACTION. Choose the supported action for your engine; neither term should be treated as a universal substitute for the other in deferred-constraint designs.
The foreign key checks existing Orders rows. It does not scan Customers to ensure that each customer has an order. Likewise, an order-line foreign key does not enforce “every submitted order has at least one line.”
If a business rule requires a minimum number of children, identify when it must hold. A draft order may temporarily have no lines, while submission requires at least one. Enforce that transition through an appropriate transactional workflow or database mechanism. A simple row-level CHECK cannot generally count related rows, and a concurrent deletion must not bypass the rule.
Mandatory participation does not automatically make an entity weak. In classical ER modeling, a weak entity depends on an owner's key for its identification. An order with its own independent OrderID can require a customer without being identified by that customer's key.
An order line identified by (OrderID, LineNo) illustrates an identifying relationship: LineNo distinguishes lines only within one order. Add this table to the Customers/Orders schema above:
CREATE TABLE OrderLine (
OrderID INT NOT NULL,
LineNo INT NOT NULL CHECK (LineNo > 0),
ItemDescription VARCHAR(200) NOT NULL,
Quantity INT NOT NULL CHECK (Quantity > 0),
CONSTRAINT pk_orderline PRIMARY KEY (OrderID, LineNo),
CONSTRAINT fk_orderline_order
FOREIGN KEY (OrderID) REFERENCES Orders(OrderID)
);
The same LineNo can be used in different orders, but a duplicate (OrderID, LineNo) pair is rejected. Each line must reference an existing order. This simplified example stores a line description; a product catalog would require its own product reference and business rules.
Cascading deletion is a lifecycle choice, not the definition of a weak entity. A restrictive foreign key also prevents orphaned lines by blocking deletion of a referenced order.
An entity can participate mandatorily in one relationship and optionally in another. For example, an order may require a customer while allowing an unassigned sales representative. Evaluate each relationship independently instead of describing the whole table as mandatory or optional.
The next lesson examines optional participation, including when an absent parent reference is meaningful.