Open In App

DROP FUNCTION and its Parameters

Last Updated : 08 Sep, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

DROP FUNCTION :
This statement could be used to remove an existing user-defined function.

Syntax :

DROP FUNCTION [ IF EXISTS ] schema_name.function_name;

Example – 

Let’s consider Geeks is the function you want to delete then use the following syntax as follows.

DROP FUNCTION Geeks;

To drop more than one user-defined functions, use below syntax :

DROP FUNCTION [IF EXISTS]  
 schema_name.function_name1,  
 schema_name.function_name2,
...;

Parameters :

  • IF EXISTS –
    IF EXISTS parameter is optional used to drop the function only if it exists. In case of removing a non-existing function without using the IF EXISTS option, SQL Server will throw an error.

  • schema_name –
    The schema_name is an optional parameter. The schema_name defines the name of the schema to which the user-defined function belongs.

  • function_name –
    The function_name is the name of the function that will be removed.

Notes : 

If there are constraints like CHECK or DEFAULT in the function, the DROP FUNCTION statement will return error.

Example –

Lets us create a function that calculates discount from amount, list, and percentage :

Creating “Geek.discount_amount” function –

CREATE FUNCTION Geek.discount_amount (
   @amount INT,
   @list DEC(10,2),
   @percentage DEC(4,2)  
) RETURNS DEC(10,2)  
AS  
BEGIN
   RETURN @quantity * @amount * @percentage
END

To drop the function, you can use the following SQL query given below.

DROP FUNCTION IF EXISTS Geek.discount_amount;

Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads