Skip to content

Latest commit

 

History

History
84 lines (63 loc) · 4 KB

drop-function-transact-sql.md

File metadata and controls

84 lines (63 loc) · 4 KB
title description author ms.author ms.date ms.service ms.subservice ms.topic f1_keywords helpviewer_keywords dev_langs monikerRange
DROP FUNCTION (Transact-SQL)
DROP FUNCTION (Transact-SQL)
WilliamDAssafMSFT
wiassaf
02/11/2020
sql
t-sql
reference
DROP_FUNCTION_TSQL
DROP FUNCTION
user-defined functions [SQL Server], removing
removing user-defined functions
DROP FUNCTION statement
dropping user-defined functions
deleting user-defined functions
TSQL
>=aps-pdw-2016||=azuresqldb-current||=azure-sqldw-latest||>=sql-server-2016||>=sql-server-linux-2017||=azuresqldb-mi-current||=fabric

DROP FUNCTION (Transact-SQL)

[!INCLUDE sql-asdb-asdbmi-asa-pdw-fabricse-fabricdw]

Removes one or more user-defined functions from the current database. User-defined functions are created by using CREATE FUNCTION and modified by using ALTER FUNCTION.

The DROP function supports natively compiled, scalar user-defined functions. For more information, see Scalar User-Defined Functions for In-Memory OLTP.

:::image type="icon" source="../../includes/media/topic-link-icon.svg" border="false"::: Transact-SQL syntax conventions

Syntax

 -- SQL Server, Azure SQL Database 

DROP FUNCTION [ IF EXISTS ] { [ schema_name. ] function_name } [ ,...n ]   
[;]
 -- Azure Synapse Analytics, Parallel Data Warehouse, Microsoft Fabric

DROP FUNCTION [IF EXISTS] [ schema_name. ] function_name
[;] 

Arguments

IF EXISTS
Conditionally drops the function only if it already exists. Available beginning with [!INCLUDEssnoversion_md] 2016 and in [!INCLUDEsssds_md].

schema_name
Is the name of the schema to which the user-defined function belongs.

function_name
Is the name of the user-defined function or functions to be removed. Specifying the schema name is optional. The server name and database name cannot be specified.

Remarks

DROP FUNCTION will fail if there are [!INCLUDEtsql] functions or views in the database that reference this function and were created by using SCHEMABINDING, or if there are computed columns, CHECK constraints, or DEFAULT constraints that reference the function.

DROP FUNCTION will fail if there are computed columns that reference this function and have been indexed.

Permissions

To execute DROP FUNCTION, at a minimum, a user must have ALTER permission on the schema to which the function belongs, or CONTROL permission on the function.

Examples

A. Dropping a function

The following example drops the fn_SalesByStore user-defined function from the Sales schema in the [!INCLUDEssSampleDBnormal] sample database. To create this function, see Example B in CREATE FUNCTION (Transact-SQL).

DROP FUNCTION Sales.fn_SalesByStore;  

See Also

ALTER FUNCTION (Transact-SQL)
CREATE FUNCTION (Transact-SQL)
OBJECT_ID (Transact-SQL)
EVENTDATA (Transact-SQL)
sys.sql_modules (Transact-SQL)
sys.parameters (Transact-SQL)