Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

View is not schema bound?

I have a select query to retrieve data from tables. It is working fine, but when there's a condition to select some 3 values, it is not giving a result. Error message;

Query processor ran out of Internal resources

I looked through INDEX seems to work fine, then I created view with that select statement, but couldn't create an index. Error message;

View is not schema bound

like image 939
Manoj Avatar asked Jul 23 '10 03:07

Manoj


People also ask

What is a schema bound view?

SCHEMABINDING. Binds the view to the schema of the underlying table or tables. When SCHEMABINDING is specified, the base table or tables cannot be modified in a way that would affect the view definition.

What does schema binding mean?

Schema binding refers to the process of associating a database view to underlying tables in order to put indexes directly on the view. This may lead to great performance benefits when using the view; however, this tighter coupling is not without drawbacks.

Can we create index on view without Schemabinding?

You Can't… The view is created with the WITH SCHEMABINDING option. You can't always predict what the query optimizer will do. If you're using Enterprise Edition, it will automatically consider the unique clustered index as an option for a query – but if it finds a “better” index, that will be used.


1 Answers

In order to create an indexed view the view needs to be schema bound to the entities that it is a view over.

To make a view schema bound, simply specify simply use WITH SCHEMABINDING in the view CREATE / UPDATE query, for example:

CREATE VIEW MyView
WITH SCHEMABINDING 
AS
-- SELECT

See this link for more information on schema binding, or the MSDN page on the CREATE VIEW statement.

However from what you have said I don't think the indexed view will necessarily help you - the message "Query processor ran out of Internal resources" means that the query processor failed to produce an execution plan for your query, which I would guess only happens with extremely complex queries.

You should try to reduce the complexity of your query somehow.

like image 141
Justin Avatar answered Sep 28 '22 08:09

Justin