Solved

How to Recompile UDF

Posted on 2004-09-23
5
1,212 Views
Last Modified: 2012-06-21
Hi,

I sort of had this question in another thread but as it evolved from another question I thought I would repost this new one.

I have a number of connected inline and scaler UDF's which need to be recoompiled from time-to-time due to changes in underlying tables during development.  

Does anyone know how to "manually" recompile these as I don't believe the sp_recompile/WITH RECOMPILE switches work for UDF's.  My understanding, and according to the documention, is they only apply to Stored Procecedures.

I currently delete every UDF from the Db and then recreate them - a bit of a chore!

Thanks for any help.

James.
0
Comment
Question by:JAMES
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 11

Expert Comment

by:ram2098
ID: 12131145
User-defined functions in SQL 2000 itself are not pre-compiled ones.

So, there is no point of re-compilation.
0
 

Author Comment

by:JAMES
ID: 12131171
OK but...

When we change the structure of the underlying tables associated with cascaded UDF's (ie. one UDF calls another and adds additional functionality / values to it and uses * to obtain the parent columns) the headings get messed up when we use the UDF's.

Dropping the tables and recreating them fixes it.  We have also tried clearing the proc cache but this does not help.
0
 
LVL 2

Accepted Solution

by:
ngolovin earned 500 total points
ID: 12131447
Hello, here is a procedure, which recompiles a UDF.
It was written pretty quickly, some time ago, when I got sick of "touching" the UDFs manually every time something changes.
It does exactly what I did manually, which is probably rather brute-force than clever.
But works anyway, though limited to functions, whose code fits in varchar(8000).


create procedure recompile_udf
(@func sysname)
as
declare @text varchar(8000)
declare @i int

if exists (select * from dbo.syscomments where id=object_id(@func)) select @text=convert(varchar(8000), c.text) from dbo.syscomments c, dbo.sysobjects o     where o.id = c.id and c.id = object_id(@func) order by c.number, c.colid

set @i=patindex('CREATE%',@text)
set @text=substring(@text,@i+6,len(@text))
if substring(@text,2,1)=' '
      set @text=ltrim(@text)
else
set @text=' '+@text
set @text='ALTER ' + @text

exec (@text)
print @text

go
0
 

Author Comment

by:JAMES
ID: 12131459
I'll give it a try and report back!

Best backup my DB first ;-)

Thanks.
0
 

Author Comment

by:JAMES
ID: 12131500
My functions are still in one piece so thanks :-)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Remove () 10 41
SQL Server Pivot 5 42
STUFF function - proper use to update column? 6 18
Importing from CSV to SSMS 2 14
Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question