In this step by step SQL Tutorial I will show you how to use DROP FUNCTION statements. For the purpose of this tutorial I will use SQL Server Management Studio 2012.
You might find this tutorial if:
- You are new to SQL and DROP FUNCTION statements
- You would like to find out how to perform DROP FUNCTION using interface and T-SQL script
- You are preparing for Microsoft Certification and DROP is not what you have used before
SQL DROP FUNCTION is used to permanently remove function from database.
Below I show you how to remove function from database using SSMS interface and using T-SQL.
In the Object Explorer I open required database in this case it is AdventureWorksDW2012 then I expand Programmability folder, Functions folder ,and scalar-valued functions (scalar-valud means this kind of functions return single value as a result) and find function which I want to remove. In this example it is dbo.Test
Below I will show you how to delete (DROP) Function from database using Object Explorer in SSMS 2012.
I open Object Explorer, AdventureWorksDW2012 database and from Programmability // Functions folder I right click dbo.Test.
From drop down box I select Delete.
In the Delete Object window I click OK.
This time I will show you how to drop finction using T-SQL
Create new query and make sure that correct database is selected on the database drop dow box on the tool bar.
SYNTAX: DROP FUNCTION SchemaName.FunctionName
The syntax is very simple and i below is my sample which I executed using Execute button.
DROP FUNCTION dbo.Test
Previously I selected database name in the drop down box and now I type drop function statement and click Execute button on the toolbar.
Function should disapper in object explorer, if it didn't right click on the database and from drop down box select Refresh option.
Below you can see that in the Functions folder the Test function has been removed.
I hope that helps you to learn and use DROP FUNCTION statement.