Sorting Views Script by Dependency
If you scripted the views for a database in Microsoft SQL Server and for some reason, the order of “create views” does not consider the dependencies of views with each other. Just try to imagine you have a hundred views to sort according to dependency and you have to figure it out manually. A software tool for this will be very handy.
Example: ---------------------------------- USE dbSAS CREATE VIEW [dbo.vwGrades] AS SELECT s.id, s.name, ssub.subjectname, g.grade from dbo.vwStudents as s inner join dbo.vwSubjects as ssub on s.id = ssub.id inner join grades as g on ssub.id = g.id order by s.name asc GO CREATE VIEW [dbo.vwSubjects] AS SELECT s.id, s.name, ssub.id, ssub.subjectname from dbo.vwStudents as s inner join student_subjects as ssub on s.id = ssub.id order by s.name asc GO CREATE VIEW [dbo.vwStudents] AS SELECT id, first + ' ' + last as name from students; GO
Executing this script in SQL Server 2005 will cause some error because the first view refers to views vwStudents and vwSubjects which are not created yet.
We have created a tool based on General SQL Parser to sort view script by dependency automatically for you.
Download this demo: C# version