Is it possible to force SQL Server to create a wrong view?



  • SQL Server has the capability to create a wrong synonym. For example:

    create synonym Sample for NonExistingObject
    

    This actually creates the Sample synonym.

    Also it's possible to create a view that works, and later change the underlying tables that the view depends upon so that the view is non-functional anymore.

    I'm creating a utility to automate some of the tasks related to the database and a lot of modules and lot of customers.

    A problem that I'm facing is that some views depend upon non-existing objects that would be added later.

    I wonder if it's possible to provide a flag to create view statement to force SQL Server to not validate view's definition and only build it?



  • No, the underlying table has to exist since sql server derives metadata for the columns that your view returns, as seen in sys.columns. You can of course create some temp stuff that the view refers to, or hardwire such as

    SELECT col1 =CAST(23 AS int)
    

    But I don't think that above is what you are looking for.

    In other words: there's no deferred name resolution för views (like there is for stored procedures).




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2