Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to Recompile UDF

Posted on 2004-09-23
5
Medium Priority
?
1,232 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 2000 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

Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

Question has a verified solution.

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

I have a large data set and a SSIS package. How can I load this file in multi threading?
Ready to get certified? Check out some courses that help you prepare for third-party exams.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

722 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