Tuesday, January 3, 2012

Drop All Functions in SQL SERVER

To DROP All function in SQL SERVER Database use following lines of codes, use it in Query window for particular database.

This code will save lots of time as DROPing All functions in SQL Server database is not a manual process, if we use this

DECLARE @name VARCHAR(128)
DECLARE @SQL VARCHAR(254)
SELECT @name = (SELECT TOP 1 [name] FROM sysobjects 
WHERE [type] IN (N'FN', N'IF', N'TF', N'FS', N'FT') 
AND category = 0 ORDER BY [name]) 
 
WHILE @name IS NOT NULL
BEGIN
    SELECT @SQL = 'DROP FUNCTION [dbo].[' + RTRIM(@name) +']'
    EXEC (@SQL)
    PRINT 'Dropped Function: ' + @name
    SELECT @name = (SELECT TOP 1 [name] FROM sysobjects 
WHERE [type] IN (N'FN', N'IF', N'TF', N'FS', N'FT') AND 
category = 0 AND [name] > @name ORDER BY [name])
END
GO





Submit this story to DotNetKicks

0 comments: