Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Repair Windows errors before they cause bigger problemsFix Now →Choose ON DELETE CASCADE when a referencing row is a dependent component that should not survive its parent. Choose ON DELETE SET NULL when the row remains useful but its relationship is optional. Choose RESTRICT or NO ACTION when deletion should be blocked while references remain. The right action reflects the records’ meaning and lifecycle—not just which setting is easiest.
What each foreign-key action does
A foreign-key action determines what happens to referencing rows when a referenced row is deleted. PostgreSQL’s documentation puts the design question plainly: “The appropriate choice of ON DELETE action depends on what kinds of objects the related tables represent.” PostgreSQL 18: Constraints
| Action | Effect when the referenced row is deleted | Use it when |
|---|---|---|
CASCADE |
Deletes matching referencing rows automatically. | The referencing rows are dependent components that cannot usefully exist without the parent. |
SET NULL |
Keeps matching referencing rows and sets the specified foreign-key columns to NULL. |
The referencing rows remain meaningful, and their relationship to the deleted row is optional. |
RESTRICT |
Prevents deletion while matching references exist. | The referencing records are independent and someone should explicitly resolve them before the parent is deleted. |
NO ACTION |
Fails if references remain when the constraint is checked. | The database’s ordinary constraint check should reject a final state that leaves references behind. |
How to choose the right action
Choose CASCADE for dependent components
Use CASCADE when a child record has no useful independent life after its parent is removed. PostgreSQL illustrates this with order items that are parts of an order. Deleting the order can therefore delete its items as well. Before using it, consider the full relationship graph: a single delete may remove many rows, and other foreign-key constraints can still prevent the overall operation. PostgreSQL 18: Constraints
Choose SET NULL for optional relationships
Use SET NULL when the referencing record should remain but can truthfully represent the lost relationship as absent. For example, a product may remain valid after its manager reference is cleared. This action does not delete the referencing row; it changes the foreign-key value.
Free tools Windows power users keep installed
One-click scans. No signup required.
#1 Best Overall
The affected foreign-key columns must allow NULL, and the resulting row must still satisfy its primary-key, check, and other constraints. In a composite foreign key, think through whether every key column should be cleared. PostgreSQL supports an optional column list for ON DELETE SET NULL, but that syntax is an extension rather than a portable assumption. PostgreSQL 18: Constraints MySQL 8.4: FOREIGN KEY Constraints Microsoft SQL Server: CREATE TABLE
Choose RESTRICT or NO ACTION to block deletion
Choose a blocking action when referencing records are independent and should be handled explicitly before the referenced record is deleted. This makes the attempted deletion fail rather than silently removing rows or clearing their associations.
RESTRICT and NO ACTION are not interchangeable in every database. Their behavior depends on the engine, particularly when deferred constraint checks are available.
RESTRICT vs. NO ACTION: timing matters
In PostgreSQL, NO ACTION is the default. A deferrable constraint can postpone its check until later in the transaction, giving the transaction a chance to repair the relationship before the check occurs. RESTRICT does not allow that delay and refuses the operation immediately. PostgreSQL 18: CREATE TABLE
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Fix the driver behind crashes, sound loss and screen glitches3Clear out junk files and repair common Windows errorsRank #3
MySQL InnoDB treats NO ACTION as equivalent to RESTRICT. SQL Server lists NO ACTION as the default. Do not infer identical timing or behavior from the names alone; consult the documentation for the database product and version you deploy. MySQL 8.4: FOREIGN KEY Constraints Microsoft SQL Server: CREATE TABLE
Check the target database before shipping
| Database and documented version | Relevant behavior |
|---|---|
| PostgreSQL 18 | NO ACTION is the default and can be deferred when the constraint is deferrable; RESTRICT blocks immediately. SET NULL clears all referencing columns by default, with an optional column subset supported for ON DELETE. PostgreSQL 18: CREATE TABLE PostgreSQL 18: Constraints |
| MySQL 8.4 | Behavior depends on storage engine. InnoDB treats NO ACTION as RESTRICT; SET NULL requires nullable child columns. InnoDB and NDB reject SET DEFAULT definitions. Confirm the engine enforces foreign keys and check the manual for the deployed release. MySQL 8.4: FOREIGN KEY Constraints |
| Microsoft SQL Server | NO ACTION is the default. SET NULL requires nullable foreign-key columns. SET DEFAULT requires defaults for all foreign-key columns, and the resulting values must satisfy the constraints. SQL Server applies combinations of cascading referential actions before checking NO ACTION; a conflict rolls back the related operations. Microsoft SQL Server: CREATE TABLE Microsoft: Primary and foreign key constraints |
Check delete and lookup performance
When a referenced row is deleted, the database must find matching referencing rows. PostgreSQL notes that declaring a foreign key does not automatically create an index on the referencing columns. Consider adding one when the delete workload or queries that look up related rows justify it; base that decision on the workload and query plan. PostgreSQL 18: Constraints
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

