0

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?

3
  • 2
    Smells a little like a design problem. Should either create the view when the objects it depends on are created or find a different implementation. If you want to provide more concrete details of the design and the end goal, maybe we can provide a better path to get there.
    – J.D.
    Jan 23, 2022 at 12:58
  • @J.D. thank you for your suggestion. I think I can not explain my problem in details here, as it makes it off-topic. Any idea on how and where can I ask it? Jan 23, 2022 at 13:08
  • You're certainly welcome to explain the problem you're trying to solve here, and if it's solvable with a reasonable database solution then it's definitely on-topic here. Otherwise a mod will move your question to StackOverflow if it's more on-topic for an application solution.
    – J.D.
    Jan 23, 2022 at 15:33

1 Answer 1

6

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).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.