I am creating menu and submenus in a table variable. ( Typical parent child records in the same table) ParentID coll is null for all Top menus. And for their child ParentID
You could do something like this:
delete from yourtable yt where not exists (select * from yourtable yt2 where yt.id = yt2.parentid) and yt.parentid is null