Check child elements before deleting (recursive check?)
Posted on 2009-04-19
When deleting a template (from tblTemplate table) I want to delete all content from tblContent based on this template, like this:
Delete tblContent where TemplateId = @TemplateId;
Delete tblTemplate where id = @TemplateId;
The big problem is that I dont want to delete anything IF a content element contains other child contents that is based on other Templates (different TemplateId's).
If all content in my contenttree is based on template1 exept Id6 who is based on template 2 it should not be possible to delete template1. This is because content with tamplate 1 contains other content based on other tamplates (ant this content need to remaint their parent content).
How do I write the SQL to check if content based on one spesific template dont contain other content based on another template? The content tree has many levels.