tags:

views:

76

answers:

3

What is the difference for a view if it is schema bounded or not?

A: 

You cannot index a view which is not schema bound.

A schema bound view is a part of schema dependency chains.

You cannot drop or alter a table which is referenced by a schema bound view, but can do it on a plain view (which will just throw a runtime error when referenced).

Quassnoi
+4  A: 

If a view is schema bound, it means that the underlying schemas cannot change. It actually prevents it from doing so.

Schema binding also allows you to index a view. You can see the importance of a static schema when applying indices.

Keep in mind that a schema binding can only take place within a database--you can't schema bind a view to another database or another server. This is entirely for data integrity reasons--you're not always guaranteed to have access to that database or server, so therefore, you cannot prevent any and all changes to the schema.

Moreover, you can't drop a table that's schema bound. This will obviously muck up its schema, so is therefore prevented.

While I keep saying, "schema," I mean the table design. This includes the columns and their data types. You cannot change a column from int to bigint on a schema bound table. Nor can you change a column's name from id to tblID. This prevention is meant solely to uphold the integrity of the view.

Eric
+1  A: 

The main benefit of SCHEMA BINDING is to avoid any accidental drop or change of an object that is referenced by other objects

Using schema binding to improve SQL Server UDF performance

rahul