HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMinor

Creating a view on a non-existing view

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
creatingviewexistingnon

Problem

I have a whole bunch of views that I need to create. Many of these views depend on other views.

If I create a view that depends on a view not yet created, I get an Invalid Object error.

Rather than go through the whole lot and work out the dependencies and then deal with creating them all in the correct order, is there a way I can just switch this checking off until all the views are created?

It is possible to delete a dependant view after the view is installed, so it is possible for the database to be in a state where a view exists that depends on a non-existent object. I need it to accept being in this state during creation..

Solution

If you have access to adatabase that the views exist within you can query sys.views to determine the order in which they where created. Query below should help with this, add a predicate to filter the list if it helps.

SELECT v.name   
FROM sys.views v
ORDER BY v.create_date

Code Snippets

SELECT v.name   
FROM sys.views v
ORDER BY v.create_date

Context

StackExchange Database Administrators Q#8094, answer score: 2

Revisions (0)

No revisions yet.