Answer the question
In order to leave comments, you need to log in
How to get the name of a function in MS SQL to pass it to DROP FUNCTION?
There is a query that displays information about all user-defined functions:
USE master
GO
SELECT name AS function_name
,object_id
,SCHEMA_NAME(schema_id) AS schema_name
,type_desc
,create_date
,modify_date
FROM sys.objects
WHERE type_desc LIKE '%FUNCTION%';
GO
DECLARE @FuncName sysname = (
SELECT MIN(name)
FROM sys.objects
WHERE type_desc LIKE '%FUNCTION%' AND SCHEMA_NAME(schema_id) = 'dbo'
)
DROP FUNCTION @FuncName
Answer the question
In order to leave comments, you need to log in
Dynamic SQL needs
DECLARE @FuncName sysname = (
SELECT MIN(name)
FROM sys.objects
WHERE type_desc LIKE '%FUNCTION%' AND SCHEMA_NAME(schema_id) = 'dbo'
)
DECLARE @SQL Varchar(200)
set @SQL ='DROP FUNCTION ' + @FuncName
EXECUTE (@sql)
Note:
If you get an error, you can try
EXECUTE IMMEDIATE (@sql)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question