June 2, 2010 at 5:52 pm
I have a sql script which creates a view. This view references a table that does not exist when the view is created. So, it throws an error. I am wondering how I can catch the error and allow the view to be created anyway with no error thrown (important). I have tried wrapping it in a try catch, but it seems that is not allowed. I have tried using an if (@@error <> 0) statement, but it doesn't stop the error from being thrown.
I just want to prevent the error from being returned at all. I have also found that Oracle has exactly what I want (CREATE FORCE VIEW), but that is not available in SQL Server.
Any ideas?
June 2, 2010 at 8:13 pm
Sorry, it's not possible with a view.
in SQL Server, only a procedure can be created where the objects it uses do not exist yet;
everything else...tables with foreign keys, views and functions require the object to exist.
Can't you change the order of your script so that the dependent items are created first?
Lowell
June 2, 2010 at 8:17 pm
Unfortunately no. The table is created manually later. It's not even in the script.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply