sql-serversql-server-2012circular-dependencycalculated-columnsschemabinding

Schema bound and computed columns dependency loop


Well this isn't good.

I have a schema-bound function called "GetFriendlyProductItem" which returns a human-readable name for a product from the ProductItems table.

The ProductItems table in turn, has a computed column called "Name" which uses this function to generate the value in this column.

The problem is that I need to make a change to ProductItems. I cannot, because GetFriendlyProductItem uses it and it is schema-bound. I tried to alter GetFriendlyProductItem so that it is no longer schema-bound. This raises the error that I cannot alter it because it is being used in the computed column in the ProductItems.

How can I make modifications to the ProductItems table when I have this loop of dependency preventing it?


Solution

  • That is easy:

    ALTER TABLE dbo.ft DROP COLUMN name;
    

    where name is the name of the computed column.

    Just make sure to save the definition somewhere...