Skip to content

Instantly share code, notes, and snippets.

@devmnj
Created July 14, 2020 15:55
Show Gist options
  • Select an option

  • Save devmnj/baec96536437761086e057055b92d960 to your computer and use it in GitHub Desktop.

Select an option

Save devmnj/baec96536437761086e057055b92d960 to your computer and use it in GitHub Desktop.
Check a function exist or not in MS SQL Server
IF EXISTS (
SELECT * FROM sysobjects WHERE id = object_id(N'function_name')
AND xtype IN (N'FN', N'IF', N'TF')
)
DROP FUNCTION function_name
GO
If you want to avoid the sys* tables, you could instead do (from here in example A):
IF object_id(N'function_name', N'FN') IS NOT NULL
DROP FUNCTION function_name
GO
The main thing to catch is what type of function you are trying to delete (denoted in the top sql by FN, IF and TF):
FN = Scalar Function
IF = Inlined Table Function
TF = Table Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment