开发者

Modifying a function used as a column default in SQL Server

开发者 https://www.devze.com 2022-12-18 06:50 出处:网络
We\'re having an iss开发者_StackOverflow中文版ue with a poorly coded SQL function(which works fine in live, but not in our test environment). This function is used to provide a default value in many t

We're having an iss开发者_StackOverflow中文版ue with a poorly coded SQL function(which works fine in live, but not in our test environment). This function is used to provide a default value in many tables, trying to ALTER the function returns a "Cannot ALTER ### because it is being referenced by object" error.

Is there any way round this error message? The only way I can think of is attempting to write a script to remove it from every table that has it as a default, altering the function and re-adding it after.


Since the object is referenced, you cannot modify it. This is what you do:

  1. Remove the default constraint from the table/column
  2. Modify the function
  3. Add the default constraint back


SQL Server will not allow you to modify a function that is bound to the DEFAULT constraint of a column.

Your only option is to remove the constraint before altering the function. (Source)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号