Delete from the lowest level up, transaction controlled
In this example, the 'Orders' table is related to 'Order Catalogue Details' which is related to 'Order Quantities'.
If you're using SQL 2005 then obviously try-catch rather than this type of error checking
BEGIN TRANSACTION
DELETE FROM order_quantities WHERE oq_catalogue_id_fk IN (SELECT ocd_id_pk FROM order_catalogue_details WHERE ocd_order_id_fk = @OrderID)
IF (@@Error !=0)
BEGIN
ROLLBACK TRANSACTION
RETURN @@ERROR
END
DELETE FROM order_catalogue_details WHERE ocd_order_id_fk = @OrderID
IF (@@Error !=0)
BEGIN
ROLLBACK TRANSACTION
RETURN @@ERROR
END
DELETE FROM orders WHERE ord_id_pk = @OrderID
IF (@@Error !=0)
BEGIN
ROLLBACK TRANSACTION
RETURN @@ERROR
END
COMMIT TRANSACTION