Reputation: 191
Is there a way to find a usage of a function in SQL server 2008?
Upvotes: 19
Views: 13711
Reputation: 69
With SQL2012, use sp_depends in your database will list all usage inside.
ex.
Upvotes: 1
Reputation: 2738
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
Upvotes: 17
Reputation: 432200
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)
Upvotes: 14
Reputation: 50273
Assuming that by "usage" you mean "usage statistics", then maybe SQL Server Profiler is useful for you.
Upvotes: -1