ALTER Function with dependencies

  • Hello,

    I want to alter a scalar function. Unfortunately SQL Server generates an error:

    => Cannot ALTER 'XXX' because it is being referenced by object 'YYY'.

    The object referencing the function is a table with a computed column.

    I read that the cause is the "WITH SCHEMABINDING"-option when creating a table, view etc...

    Is it possible to "deactivate" this option temporarily, so that I am able to alter my function? Otherwise I have to drop the table (or delete the referencing columns), alter the function and create the table (or the referencing columns) again.

    Thank you very much!

  • You would need to drop this column, alter the function, add the column again. (I assume that it is not a persisted column, so it should be reasonable fast). If the dependency chain is much longer, you may want to look at third party tools that can generate these change scripts for you automatically.

    Regards,

    Andras


    Andras Belokosztolszki, MCPD, PhD
    GoldenGate Software

  • Thank you for your answer. Can you tell me where I can find such tools?

  • Jetro (11/14/2007)


    Thank you for your answer. Can you tell me where I can find such tools?

    Red Gate's SQL Compare is one (it compares database schemata, and generates the change script). But it can also do this using SQL scripts, so you can script your database, modify the tables, udf, ... and then SQL Compare will create a migration script (and it will do its best to preserve the data in the tables).

    Disclaimer: I wrote a large part of this tool and I do work for Red Gate. There are other alternatives, but the one I mentioned is the one I know the best.

    Regards,

    Andras


    Andras Belokosztolszki, MCPD, PhD
    GoldenGate Software

  • Andras Belokosztolszki (11/14/2007)


    Disclaimer: I wrote a large part of this tool and I do work for Red Gate. There are other alternatives, but the one I mentioned is the one I know the best.

    If it makes you feel any better Andras I've used RedGate and SQL Delta and I generally prefer RedGate. Although SQL Delta works just fine.

    Kenneth FisherI was once offered a wizards hat but it got in the way of my dunce cap.--------------------------------------------------------------------------------For better, quicker answers on T-SQL questions, click on the following... http://www.sqlservercentral.com/articles/Best+Practices/61537/[/url]For better answers on performance questions, click on the following... http://www.sqlservercentral.com/articles/SQLServerCentral/66909/[/url]Link to my Blog Post --> www.SQLStudies.com[/url]

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply