4

How can I delete all function from my database using sql-script. I tried:

declare @nm varchar(100)
select @nm = name from sysobjects where type = 'FN'
exec('drop function ' + @nm)

And I put in into the loop but it not delete all function. Please help

  • Please show us the loop. Also, when you say "not delete all function" what functions are left? How many are deleted? – chrisl08 Sep 10 '15 at 16:56

1 Answers1

17
Declare @sql NVARCHAR(MAX) = N'';

SELECT @sql = @sql + N' DROP FUNCTION ' 
                   + QUOTENAME(SCHEMA_NAME(schema_id)) 
                   + N'.' + QUOTENAME(name)
FROM sys.objects
WHERE type_desc LIKE '%FUNCTION%';

Exec sp_executesql @sql
GO
M.Ali
  • 67,945
  • 13
  • 101
  • 127