DROP FUNCTION (Transact-SQL)DROP FUNCTION (Transact-SQL)

適用於: 是SQL Server 是Azure SQL Database 是Azure SQL 資料倉儲 是平行處理資料倉儲 APPLIES TO: yesSQL Server yesAzure SQL Database yesAzure SQL Data Warehouse yesParallel Data Warehouse

從目前資料庫移除一或多個使用者自訂函數。Removes one or more user-defined functions from the current database. 使用者定義函數是使用 CREATE FUNCTION 建立的,並使用 ALTER FUNCTION 加以修改。User-defined functions are created by using CREATE FUNCTION and modified by using ALTER FUNCTION.

DROP 函數支援原生編譯的純量使用者定義函數。The DROP function supports natively compiled, scalar user-defined functions. 如需詳細資訊,請參閱記憶體內部 OLTP 的純量使用者定義函數For more information, see Scalar User-Defined Functions for In-Memory OLTP.

主題連結圖示 Transact-SQL 語法慣例Topic link icon Transact-SQL Syntax Conventions

語法Syntax

 -- SQL Server, Azure SQL Database 

DROP FUNCTION [ IF EXISTS ] { [ schema_name. ] function_name } [ ,...n ]   
[;]
 -- Azure SQL Data Warehouse, Parallel Data Warehouse 

DROP FUNCTION [ schema_name. ] function_name
[;] 

引數Arguments

IF EXISTS IF EXISTS
只有在函數已存在時,才能有條件地將其卸除。Conditionally drops the function only if it already exists. SQL ServerSQL Server 2016 和 SQL DatabaseSQL Database 開始可用。Available beginning with SQL ServerSQL Server 2016 and in SQL DatabaseSQL Database.

schema_nameschema_name
這是使用者定義函數所屬的結構描述名稱。Is the name of the schema to which the user-defined function belongs.

function_namefunction_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.

RemarksRemarks

如果資料庫中有 Transact-SQLTransact-SQL 函數或檢視參考這個函數,並且是利用 SCHEMABINDING 加以建立;或者如果有計算資料行、CHECK 條件約束或 DEFAULT 條件約束參考這個函數,DROP FUNCTION 就不會成功。DROP FUNCTION will fail if there are Transact-SQLTransact-SQL 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 就不會成功。DROP FUNCTION will fail if there are computed columns that reference this function and have been indexed.

權限Permissions

若要執行 DROP FUNCTION,使用者至少必須對該函數所屬的結構描述具備 ALTER 權限,或是對該函數具備 CONTROL 權限。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.A. 卸除函數Dropping a function

下列範例會從 AdventureWorks2012AdventureWorks2012 範例資料庫的 Sales 結構描述,卸除 fn_SalesByStore 使用者定義的函數。The following example drops the fn_SalesByStore user-defined function from the Sales schema in the AdventureWorks2012AdventureWorks2012 sample database. 若要建立此函數,請參閱範例 B 中的 CREATE FUNCTION & #40;TRANSACT-SQL & #41;To create this function, see Example B in CREATE FUNCTION (Transact-SQL).

DROP FUNCTION Sales.fn_SalesByStore;  

另請參閱See Also

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