Na serveru SQL Server:Použijte rekurzivní dotaz. Vzhledem k tomu, CREATE TABLE tmp(Id int, Parent int), použijte
WITH x(Id) AS (
SELECT @Id
UNION ALL
SELECT tmp.Id
FROM tmp
JOIN x ON tmp.Parent = x.Id
)
DELETE tmp
FROM x
JOIN tmp ON tmp.Id = x.Id