Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot DROP FUNCTION because it is being referenced by object

I got this error while trying to drop some User Defined Functions.

Msg 3729, Level 16, State 1, Line 13
Cannot DROP FUNCTION 'dbo.testfn2' because it is being referenced by object 'testtable2'.

Msg 3729, Level 16, State 1, Line 14
Cannot DROP FUNCTION 'dbo.testfn' because it is being referenced 
by object 'DF__testtable__idc__5CD6CB2B'.

One reason for this error was some columns were using the function in their default constraints.

I tried removing all default constraints.

But there are reasons other than this.

What are the other possibilities?

like image 401
jophab Avatar asked Mar 28 '26 16:03

jophab


1 Answers

To show dependencies you can use sp_depends procedure:

exec sp_depends 'dbo.YourFunc'

Or, call sys.dm_sql_referencing_entities table valued function:

SELECT * FROM sys.dm_sql_referencing_entities('dbo.YourFunc','OBJECT')
like image 187
Paweł Dyl Avatar answered Mar 30 '26 06:03

Paweł Dyl