简体   繁体   中英

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, ie 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM