Hi,
I have a list of objects that will be modified, and I would like to write a query to order by dependencies in a way that it would not fail because one depends on the other.
Here is what I have so far:
CREATE TABLE #objects(name NVARCHAR(100)
);
--List of objects
INSERT INTO #objects
select 'item'
union
select 'order'
union
select 'order_detail';
SELECT name FROM (
SELECT DISTINCT referenced_entity_name, ISNULL(referenced_id,-1) AS referenced_id, name
FROM sys.sql_expression_dependencies
RIGHT OUTER JOIN #objects
ON name = OBJECT_NAME(referenced_id)) AS a
ORDER BY
CASE WHEN a.referenced_id = '-1' THEN 2 ELSE 1 END, referenced_id ASC Any thoughts on how to write this query?
- Edited by Rodrigo Lira Guthrie 1 hour 11 minutes ago