Alex Rivera | Logout

Downsides to "WITH SCHEMABINDING" in SQL Server?

Asked 2009-11-02T03:37:19.787
65

I have a database with hundreds of awkwardly named tables in it (CG001T, GH066L, etc)
and I have views on every one with its "friendly" name (e.g. view CUSTOMERS is SELECT * FROM GG120T).

I want to add "WITH SCHEMABINDING" to my views so that I can have some of the advantages associated with it, like being able to index the view, since a handful of views have computed columns that are expensive to compute on the fly.

Are there downsides to SCHEMABINDING these views?

I've found some articles that vaguely allude to the downsides, but never go into them in detail.

I know that once a view is schema-bound, you can't alter anything that would impact the view (for example, a column datatype or collation) without first dropping the view.
Anything aside from that?

It seems that the ability to index the view itself would far outweigh the downside of planning your schema modifications more carefully.

Edit
Report

2 Answers

36

Oh, there are DEFINITELY DOWNSIDES to using SCHEMABINDING - these come from fact the SCHEMABINDING, especially when coupled with COMPUTED columns "LOCKS" THE RELATIONSHIPS and makes some "trivial changes" darn near impossible.

  1. Create a table.
  2. Create a SCHEMABOUND UDF.
  3. Create a COMPUTED PERSISTED column that references the UDF.
  4. Add an INDEX over said column.
  5. Try to update the UDF.

Good luck with that one!

  1. The UDF can't be dropped or altered because it is SCHEMABOUND.
  2. The COLUMN can't be dropped because it is used in an INDEX.
  3. The COLUMN can't be altered because it is COMPUTED.

Well, frak. Really..!?! My day just became a PITA. (Now, tools like ApexSQL Diff can handle this when provided with a modified schema, but the issue is here that I can't even modify the schema to begin with!)

I'm not against SCHEMABINDING, mind (and it's needed for a UDF in this case), but I'm against there not being a way (that I can find) to "temporarily disable" the SCHEMABINDING.

answered 2013-07-02T01:41:24.237
35

None at all. It's safer. we use it everywhere.

answered 2009-11-02T09:30:18.137

Your Answer