HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

Can I alter a view being referenced with schemabinding if the change fulfills the binding requirement?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
canthereferencedwithschemabindingviewbeingrequirementbindingfulfills

Problem

In SQL Server 2008, I have views WITH SCHEMABINDING and I need to alter one.

I am changing a column while not changing its alias so consumers will be unaffected.

If I were to drop all my other views that depend on this I would be able to recreate them again, so SCHEMABINDING is still valid.

Can I temporarily disable the schema lock on this view in order to ALTER it?

Or must I drop the dependent views and recreate them once it's changed?

Solution

You don't need to drop the dependent views, but you do need to alter them to (temporarily) not be schemabinding. If any of them are indexed, this means you will need to re-create the indexes.

SQL Server doesn't have some weighting system for schemabinding: you can't change the object. Period.

ALTER VIEW dbo.view_name
--Remove this WITH SCHEMABINDING
AS
  SELECT ...

Code Snippets

ALTER VIEW dbo.view_name
--Remove this WITH SCHEMABINDING
AS
  SELECT ...

Context

StackExchange Database Administrators Q#58801, answer score: 9

Revisions (0)

No revisions yet.