Sunday, April 18, 2010

UDFs and Underlying Schema Changes

I had a problem at work recently where we changed a column's collation but a User Defined Function that referenced this column didn't reflect the updates and started complaining about collation conflicts. In this situation, most people (at least most people I know) recommend dropping the UDF and recreating it to force the UDF to update, but there is a better way.

sp_refreshsqlmodule will refresh the UDF in a single step and without the risk in dropping an object. The MSDN documentation for CREATE FUNCTION (under Best Practices) recommends creating functions WITH SCHEMABINDING as an alternative.

0 comments: