Drop Function if exist – SQL Server

Author posted by Jitendra on Posted on under category Categories SQL, SQL Server and tagged as Tags , with Leave a comment on Drop Function if exist – SQL Server

Drop the user define function from database if it exists.

Below script will help to drop the scalar function present in SQL Server 2005 if exist.

It is always good practice to write the drop statement before creating any stored procedure or the database function.
Lets say the function name is fn_GetFirstDayOfWeek

IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[fn_GetFirstDayOfWeek]')
AND type in (N'FN', N'IF',N'TF', N'FS', N'FT'))
DROP FUNCTION [dbo].[fn_GetFirstDayOfWeek]

Related posts

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.