Josh
Josh

Reputation: 8477

Ignore dependency when creating view in SQL Server

I'm creating a build script for a database and building the views in alphabetical order. An issue I've run into is that a view is created before a view that is referenced in the definition. The referenced view is created later in the script. Is there a command I can use that would create a view without validating, i.e. ignore the dependencies?

Note: Stored Procedures have the concept of "deferred name resolution" but I don't see a way of using this for views.

Upvotes: 3

Views: 5471

Answers (1)

mellamokb
mellamokb

Reputation: 56789

To add to @Joe Stefanelli's comment, there are many ways to script SQL objects in the correct order of dependency.

  1. Listing the dependency order from the SSMS UI.
  2. Use sp_depends to find dependency order, or using built-in dependency info tables.
  3. Generate the script using the SSMS Tasks -> Generate Scripts... wizard, which can actually be automated using tools like Scriptio or built-in .NET SMO Library.

Another poor man's solution is just to run the script as many times as you have layers of dependencies. Existing objects would be ignored, and each execution would create more objects that depend on earlier-created objects. I would not recommend this solution if at all possible to find something more direct, as mentioned in the list above.

Upvotes: 2

Related Questions