Like this? It seems easiest just to do it as three separate statements.
DELETE FROM Products WHERE SubCatId IN (SELECT SubCatID FROM SubCategory WHERE MainCatId = @mainCatId);
DELETE FROM SubCategory WHERE MainCatId = @mainCatId;
DELETE FROM MainCategory WHERE MainCatId = @mainCatId;
8
solved Delete query to delete data from multiple tables in sql server and c#