Created
July 14, 2020 15:55
-
-
Save devmnj/baec96536437761086e057055b92d960 to your computer and use it in GitHub Desktop.
Check a function exist or not in MS SQL Server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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