Here is a query that produces DELETE statement. I'm a little uncertain whether MIN maybe should be MAX. With some luck it may not matter.
WITH rekurs AS (
SELECT object_id('YourSchema.YourTable') AS table_id, level = 1
UNION ALL
SELECT fk.parent_object_id, level = level + 1
FROM sys.foreign_keys fk
JOIN rekurs r ON fk.referenced_object_id = r.table_id
)
SELECT 'DELETE ' + quotename(s.name) + '.' + quotename(t.name) AS delstmt, MIN(r.level) AS level
FROM rekurs r
JOIN sys.tables t ON r.table_id = t.object_id
JOIN sys.schemas s ON s.schema_id = t.schema_id
GROUP BY s.name, t.name
ORDER BY level DESC, s.name, t.name
You may get this error message:
Msg 530, Level 16, State 1, Line 27 The statement terminated. The maximum recursion 100 has been exhausted before statement completion.
That would happen if you have circular dependencies. That is table A has an FK to B and B has an FK to A.