What does ON DELETE CASCADE do?
ON DELETE CASCADE is a foreign key option: when a row in the parent table is deleted, SQL Server automatically deletes the rows in the child table that reference it, in the same statement. The option belongs to the child’s foreign key, not to the parent table, and each foreign key has its own. A foreign key without it has the default action, NO ACTION, and the delete is refused while child rows exist.
The examples are an online shop cut down from the online shopping system template: customers place orders, an order has items, and each item sells a product. One key cascades, the one from an item to its order:
CREATE TABLE dbo.Customer ( CustomerId int IDENTITY NOT NULL CONSTRAINT PK_Customer PRIMARY KEY, Email nvarchar(254) NOT NULL, FullName nvarchar(200) NOT NULL ); CREATE TABLE dbo.Product ( ProductId int IDENTITY NOT NULL CONSTRAINT PK_Product PRIMARY KEY, Sku varchar(20) NOT NULL, Name nvarchar(200) NOT NULL, Price decimal(10, 2) NOT NULL ); CREATE TABLE dbo.CustomerOrder ( CustomerOrderId int IDENTITY NOT NULL CONSTRAINT PK_CustomerOrder PRIMARY KEY, CustomerId int NOT NULL, PlacedAt datetime2(0) NOT NULL, CONSTRAINT FK_CustomerOrder_Customer_CustomerId FOREIGN KEY (CustomerId) REFERENCES dbo.Customer (CustomerId) ); CREATE TABLE dbo.OrderItem ( CustomerOrderId int NOT NULL, ProductId int NOT NULL, Quantity smallint NOT NULL, UnitPrice decimal(10, 2) NOT NULL, CONSTRAINT PK_OrderItem PRIMARY KEY (CustomerOrderId, ProductId), CONSTRAINT FK_OrderItem_CustomerOrder_CustomerOrderId FOREIGN KEY (CustomerOrderId) REFERENCES dbo.CustomerOrder (CustomerOrderId) ON DELETE CASCADE, CONSTRAINT FK_OrderItem_Product_ProductId FOREIGN KEY (ProductId) REFERENCES dbo.Product (ProductId) );

Ana has two orders and Ben one, with five items between them. The last statement deletes Ben’s order:
INSERT INTO dbo.Customer (Email, FullName) VALUES (N'ana@example.com', N'Ana Silva'), (N'ben@example.com', N'Ben Okafor'); INSERT INTO dbo.Product (Sku, Name, Price) VALUES ('MUG-01', N'Mug', 9.50), ('TEE-02', N'T-shirt', 18.00), ('CAP-03', N'Cap', 12.00); INSERT INTO dbo.CustomerOrder (CustomerId, PlacedAt) VALUES (1, '2026-05-04 10:12'), (1, '2026-06-11 18:40'), (2, '2026-06-12 09:05'); INSERT INTO dbo.OrderItem (CustomerOrderId, ProductId, Quantity, UnitPrice) VALUES (1, 1, 2, 9.50), (1, 2, 1, 18.00), (2, 2, 2, 18.00), (2, 3, 1, 12.00), (3, 1, 1, 9.50); DELETE FROM dbo.CustomerOrder WHERE CustomerOrderId = 3;
SQL Server reports 1 row affected, and order 3’s one item is gone with it. The count is the rows of the table the DELETE names; what the cascade removed isn’t in it.
What NO ACTION does instead: Msg 547 on delete
The other two keys say nothing, so they are NO ACTION. Deleting a product that is still on an order, or a customer who still has orders, fails:
DELETE FROM dbo.Product WHERE ProductId = 2; DELETE FROM dbo.Customer WHERE CustomerId = 1;
Msg 547, Level 16, State 1, Line 1
The DELETE statement conflicted with the REFERENCE constraint "FK_OrderItem_Product_ProductId". The conflict occurred in database "Shop", table "dbo.OrderItem", column 'ProductId'.
The statement has been terminated.
Msg 547, Level 16, State 1, Line 2
The DELETE statement conflicted with the REFERENCE constraint "FK_CustomerOrder_Customer_CustomerId". The conflict occurred in database "Shop", table "dbo.CustomerOrder", column 'CustomerId'.
The statement has been terminated.The T-shirt is on orders 1 and 2, and Ana still has both her orders, so neither row goes and nothing else changes. On a delete, Msg 547 names a REFERENCE constraint, the parent’s side of the key. Inserting a child whose parent doesn’t exist raises the same number from the child’s side, which the INSERT statement conflicted with the FOREIGN KEY constraint covers.
For a product, the refusal is the right answer. A product that was sold stays in the catalog, marked discontinued if need be, because past orders still describe it. The refusal is also what keeps an order item from becoming an orphan, a row whose foreign key points at nothing.
Other databases call this RESTRICT. SQL Server has no such action: NO ACTION does its job, and ON DELETE RESTRICT is a syntax error, Msg 156, “Incorrect syntax near the keyword ‘RESTRICT’.”
ON DELETE SET NULL, SET DEFAULT and ON UPDATE CASCADE
SQL Server has four actions: NO ACTION, CASCADE, SET NULL and SET DEFAULT. The last two keep the child rows. SET NULL empties the foreign key, so its column must allow NULL. Categories suit it: removing a category shouldn’t remove the products filed under it.
CREATE TABLE dbo.Category ( CategoryId int IDENTITY NOT NULL CONSTRAINT PK_Category PRIMARY KEY, Name nvarchar(100) NOT NULL ); ALTER TABLE dbo.Product ADD CategoryId int NULL, CONSTRAINT FK_Product_Category_CategoryId FOREIGN KEY (CategoryId) REFERENCES dbo.Category (CategoryId) ON DELETE SET NULL;

INSERT INTO dbo.Category (Name) VALUES (N'Kitchen'), (N'Clothing'); UPDATE dbo.Product SET CategoryId = 1 WHERE ProductId = 1; UPDATE dbo.Product SET CategoryId = 2 WHERE ProductId IN (2, 3); DELETE FROM dbo.Category WHERE CategoryId = 2; SELECT ProductId, Name, CategoryId FROM dbo.Product;
Deleting Clothing keeps the T-shirt and the cap, their CategoryId now NULL, and the mug stays in Kitchen. SET DEFAULT writes the column’s default instead, which has to be the key of a parent row that exists, such as an Uncategorized category. Both have a column they can’t work on. SET NULL on a NOT NULL column fails as the key is added, with Msg 1761; SET DEFAULT on a NOT NULL column with no default fails with Msg 1762; and a default that names no parent row lets the key in but makes the delete fail with Msg 547, worded “The DELETE statement conflicted with the FOREIGN KEY constraint”.
Each action can also be set ON UPDATE, for a change of the parent’s key value: ON UPDATE CASCADE writes the new value into every child row. In this shop it would never run. Every key is an identity, and SQL Server refuses to change one: UPDATE dbo.CustomerOrder SET CustomerOrderId = 9 fails with Msg 8102, “Cannot update identity column ‘CustomerOrderId’.” The update action matters on a key people can edit, such as a SKU or an email address that other tables reference.
How many rows a cascade deletes
Now give the customer key a cascade too. A foreign key’s action can’t be altered; drop the key and add it again with the action, as the script does. The diagram doesn’t change, since an action isn’t drawn. It runs inside a transaction, so the test leaves nothing behind:
BEGIN TRANSACTION; ALTER TABLE dbo.CustomerOrder DROP CONSTRAINT FK_CustomerOrder_Customer_CustomerId; ALTER TABLE dbo.CustomerOrder ADD CONSTRAINT FK_CustomerOrder_Customer_CustomerId FOREIGN KEY (CustomerId) REFERENCES dbo.Customer (CustomerId) ON DELETE CASCADE; SELECT (SELECT COUNT(*) FROM dbo.CustomerOrder) AS Orders, (SELECT COUNT(*) FROM dbo.OrderItem) AS Items; DELETE FROM dbo.Customer WHERE CustomerId = 1; SELECT (SELECT COUNT(*) FROM dbo.CustomerOrder) AS Orders, (SELECT COUNT(*) FROM dbo.OrderItem) AS Items; ROLLBACK;
Before the delete, the shop holds two orders and four items, all of them Ana’s. The DELETE reports 1 row affected. After it, both counts are 0: one statement removed seven rows, and six of them were never named in it. ROLLBACK undoes the delete and the changed key alike, because DDL in SQL Server is part of the transaction.
Nothing in the output tells you about those six rows. The child tables’ AFTER DELETE triggers do fire for them, once every cascade has run (triggers and cascading actions), but that only helps if somebody wrote one. Two habits help instead. Before a delete on a parent you don’t know well, run it in a transaction, count the child tables and roll back, as above. And know which keys cascade:
SELECT fk.name, OBJECT_NAME(fk.parent_object_id) AS child, OBJECT_NAME(fk.referenced_object_id) AS parent, fk.delete_referential_action_desc FROM sys.foreign_keys AS fk WHERE fk.delete_referential_action <> 0;
In this database it lists two keys: FK_OrderItem_CustomerOrder_CustomerOrderId as CASCADE and FK_Product_Category_CategoryId as SET_NULL. The customer key is back to NO ACTION after the rollback.
Which foreign keys should cascade?
Cascade only down an ownership chain: from a parent to the rows that are part of it. Three questions decide it for a child table:
- Is the child row created as part of the parent, in the same piece of work?
- Can it ever move to another parent?
- Does anyone need it once the parent is gone?
An order item passes: it is written with its order, never moves, and means nothing without it. A customer’s cart and its items, in the template, pass too. A customer’s orders fail the third question. The shop keeps them for its books, for returns and for tax, long after the customer closes the account. With the cascade, the delete above erased two sales along with the customer. Msg 547 is the useful outcome there: it tells whoever runs the delete that orders exist, and the application decides what closing an account means, such as clearing the customer’s name and email and keeping the row.
The diagram can’t make the call for you. Both lines into dbo.OrderItem are solid, because CustomerOrderId and ProductId are both in its primary key, yet the item belongs to its order and only refers to its product, so ownership is decided key by key.
Two cascade paths to one table: Msg 1785
Shipping adds two tables. A shipment belongs to its order and a shipment item to its shipment, so both keys cascade. A shipment item also points at the order item it ships, and that key is declared CASCADE as well:
CREATE TABLE dbo.Shipment ( ShipmentId int IDENTITY NOT NULL CONSTRAINT PK_Shipment PRIMARY KEY, CustomerOrderId int NOT NULL, ShippedAt datetime2(0) NOT NULL, CONSTRAINT FK_Shipment_CustomerOrder_CustomerOrderId FOREIGN KEY (CustomerOrderId) REFERENCES dbo.CustomerOrder (CustomerOrderId) ON DELETE CASCADE ); CREATE TABLE dbo.ShipmentItem ( ShipmentId int NOT NULL, ProductId int NOT NULL, CustomerOrderId int NOT NULL, Quantity smallint NOT NULL, CONSTRAINT PK_ShipmentItem PRIMARY KEY (ShipmentId, ProductId), CONSTRAINT FK_ShipmentItem_Shipment_ShipmentId FOREIGN KEY (ShipmentId) REFERENCES dbo.Shipment (ShipmentId) ON DELETE CASCADE ); ALTER TABLE dbo.ShipmentItem ADD CONSTRAINT FK_ShipmentItem_OrderItem_CustomerOrderId_ProductId FOREIGN KEY (CustomerOrderId, ProductId) REFERENCES dbo.OrderItem (CustomerOrderId, ProductId) ON DELETE CASCADE;

Msg 1785, Level 16, State 1, Line 23
Introducing FOREIGN KEY constraint 'FK_ShipmentItem_OrderItem_CustomerOrderId_ProductId' on table 'ShipmentItem' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints.
Msg 1750, Level 16, State 1, Line 23
Could not create constraint or index. See previous errors.Deleting an order would now reach dbo.ShipmentItem twice. The new tables are still empty, and SQL Server refuses the key that opens the second path anyway: what it weighs is where the declared actions could lead, whatever the tables hold. A self-referencing key with a cascade gets the same message for a cycle of one table, the case the unary relationship post walks through. The message asks for NO ACTION on one of the keys, and the ownership questions pick which: a shipment item is part of its shipment and only refers to the order item it ships.
ALTER TABLE dbo.ShipmentItem ADD CONSTRAINT FK_ShipmentItem_OrderItem_CustomerOrderId_ProductId FOREIGN KEY (CustomerOrderId, ProductId) REFERENCES dbo.OrderItem (CustomerOrderId, ProductId);

Order 2 ships in one shipment with both its items:
INSERT INTO dbo.Shipment (CustomerOrderId, ShippedAt) VALUES (2, '2026-06-13 08:30'); INSERT INTO dbo.ShipmentItem (ShipmentId, ProductId, CustomerOrderId, Quantity) VALUES (1, 2, 2, 2), (1, 3, 2, 1); DELETE FROM dbo.OrderItem WHERE CustomerOrderId = 2 AND ProductId = 3; DELETE FROM dbo.CustomerOrder WHERE CustomerOrderId = 2;
Msg 547, Level 16, State 1, Line 6
The DELETE statement conflicted with the REFERENCE constraint "FK_ShipmentItem_OrderItem_CustomerOrderId_ProductId". The conflict occurred in database "Shop", table "dbo.ShipmentItem".
The statement has been terminated.Taking the cap off order 2 fails with Msg 547: an item that has shipped can’t vanish from under its shipment. Deleting the whole order works. It takes the order, its two items, its shipment and the shipment’s two items, six rows for a reported one. SQL Server applies every cascade of a statement before it checks the NO ACTION keys, so by the time it checks the shipment item’s key to the order item, the shipment items are already gone.
How ERDsmith helps
The customer cascade that erased Ana’s sales and the second path into dbo.ShipmentItem were both decided in the DDL, and SQL Server spoke up about only one of them, once the script ran. Which keys cascade is part of the design, so ERDsmith keeps the actions on each relationship and checks them as you set them:
- The customer key would have stayed NO ACTION: a new relationship takes the project’s default actions, on delete and on update, and that default is NO ACTION until someone sets it, so a cascade is a step somebody takes on purpose.
- Setting the order item’s key on
dbo.ShipmentItemto CASCADE marksdbo.ShipmentItemas an error with Msg 1785’s number, as soon as the second path exists; a cycle, a self-reference or two keys to one parent get the same mark. - Setting that key back to NO ACTION, the fix the script needed, clears the mark.