Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find usage of a function in SQL server

Is there a way to find a usage of a function in SQL server 2008?

like image 979
frostred Avatar asked Nov 30 '09 10:11

frostred


2 Answers

Use in code:

SELECT * FROM sys.sql_modules WHERE definition LIKE '%MyFunc%'
UNION
SELECT * FROM sys.computed_columns WHERE definition LIKE '%MyFunc%'
UNION
SELECT * FROM sys.check_constraints WHERE definition LIKE '%MyFunc%'
UNION
SELECT * FROM sys.default_constraints WHERE definition LIKE '%MyFunc%'

I think I've covered all bases...

You can't use sys.comments because the type is nvarchar(4000)

like image 158
gbn Avatar answered Oct 18 '22 15:10

gbn


The answer for SQL Server 2012:

SELECT DISTINCT sc.id, 
                so.name 
FROM   syscomments sc 
       INNER JOIN sysobjects so 
         ON so.id = sc.id 
WHERE  sc.TEXT LIKE '%functionname%' 
ORDER  BY 2 

enter image description here

like image 38
Cosmin Onea Avatar answered Oct 18 '22 15:10

Cosmin Onea