Scripting views / stored procedures in the order of Dependency
Any smart way to script views / stored procedure in the order of dependencie? example:
Views: A, B
Dependencies: A depends on B
By default SMO is scripting them in the alphabetical order so the create view A first and create view B follows it which makes the script un usable as create view A fails as view B doesn't exists in the database.
The way i am using to get around this setuation is, using the bellow code (asume that we are passing a list of View objects:
staticvoid SortViews(Database sourceDB,List<SqlSmoObject> smoObjects)
{
DependencyWalker dw;
DependencyTree dt;
dw =newDependencyWalker(sourceDB.Parent);
dt =newDependencyTree(dw.DiscoverDependencies(smoObjects.ToArray(),true));
smoObjects.Clear();
foreach (DependencyCollectionNode din dw.WalkDependencies(dt))
if (d.Urn.Type =="View")
smoObjects.Add(sourceDB.Views[d.Urn.GetNameForType(d.Urn.Type)]);
}
Is there any other smart / simple way to do this?

