DROP FUNCTION :
This statement could be used to remove an existing user-defined function.
DROP FUNCTION [ IF EXISTS ] schema_name.function_name;
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, ...;
- 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.
If there are constraints like CHECK or DEFAULT in the function, the DROP FUNCTION statement will return error.
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;
- Difference between DELETE and DROP in SQL
- Difference between DROP and TRUNCATE in SQL
- Difference between DELETE, DROP and TRUNCATE
- Create, Alter and Drop schema in MS SQL Server
- CREATE and DROP INDEX Statement in SQL
- SQL | DROP, TRUNCATE
- SQL | ALTER (ADD, DROP, MODIFY)
- MySQL | DROP USER
- Drop login in SQL Server
- DROP SCHEMA in SQL Server
- Hex() and Oct() Function Function in MS Access
- SLN() and SYD() Function Function in MS Access
- DDB () and FV() Function Function in MS Access
- Char_Length()Function AND ASCII() Function in MariaDB
- MySQL | LEAD() and LAG() Function
- Val() and Sum() Function in MS Access
- Sgn() and Sqr() function in MS Access
- StrConv() and StrReverse() Function in MS Access
- Chr() and Asc() Function in MS Access
- SIN() and COS() Function in SQL Server
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.