Open In App

DROP FUNCTION and its Parameters

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 :

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;
Article Tags :
SQL