DROP RULE (Transact-SQL)DROP RULE (Transact-SQL)

適用於: 是SQL Server (從 2008 開始) 否Azure SQL Database 否Azure SQL 資料倉儲 否平行處理資料倉儲 APPLIES TO: yesSQL Server (starting with 2008) noAzure SQL Database noAzure SQL Data Warehouse noParallel Data Warehouse

從目前資料庫移除一或多個使用者自訂的規則。Removes one or more user-defined rules from the current database.

重要

DROP DEFAULT 會在 MicrosoftMicrosoft[SQL Server]SQL Server 的下一個版本中移除。DROP RULE will be removed in the next version of MicrosoftMicrosoft[SQL Server]SQL Server. 請勿在新的開發工作中使用 DROP RULE,並規劃修改目前使用 DROP RULE 的應用程式。Do not use DROP RULE in new development work, and plan to modify applications that currently use them. 請改用 CHECK 條件約束,您可以利用 CREATE TABLEALTER TABLE 的 CHECK 關鍵字加以建立。Instead, use CHECK constraints that you can create by using the CHECK keyword of CREATE TABLE or ALTER TABLE. 如需詳細資訊,請參閱 Unique Constraints and Check ConstraintsFor more information, see Unique Constraints and Check Constraints.

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

語法Syntax

DROP RULE [ IF EXISTS ] { [ schema_name . ] rule_name } [ ,...n ] [ ; ]  

引數Arguments

IF EXISTSIF EXISTS
適用於[SQL Server]SQL Server (SQL Server 2016 (13.x)SQL Server 2016 (13.x)目前版本)。Applies to: [SQL Server]SQL Server ( SQL Server 2016 (13.x)SQL Server 2016 (13.x) through current version).

只有在規則已存在時,才能有條件地將其卸除。Conditionally drops the rule only if it already exists.

schema_nameschema_name
這是規則所屬的結構描述名稱。Is the name of the schema to which the rule belongs.

rulerule
這是要移除的規則。Is the rule to be removed. 規則名稱必須符合識別碼的規則。Rule names must comply with the rules for identifiers. 您可以選擇性地指定規則結構描述名稱。Specifying the rule schema name is optional.

RemarksRemarks

若要卸除規則,且規則目前繫結了資料行或別名資料類型,請先將它解除繫結。To drop a rule, first unbind it if the rule is currently bound to a column or to an alias data type. 若要解除繫結規則,請使用 sp_unbindruleTo unbind the rule, use sp_unbindrule. 如果您試圖卸除規則時,規則仍是繫結的,便會出現一則錯誤訊息,且會取消 DROP RULE 陳述式。If the rule is bound when you try to drop it, an error message is displayed and the DROP RULE statement is canceled.

在卸除規則之後,會輸入規則先前管理的資料行中所輸入的新資料,但不會有規則的條件約束。After a rule is dropped, new data entered into the columns previously governed by the rule is entered without the constraints of the rule. 現有資料完全不會受到影響。Existing data is not affected in any way.

DROP RULE 陳述式不適用於 CHECK 條件約束。The DROP RULE statement does not apply to CHECK constraints. 如需有關卸除 CHECK 條件約束的詳細資訊,請參閱 ALTER TABLE (Transact-SQL)For more information about dropping CHECK constraints, see ALTER TABLE (Transact-SQL).

[權限]Permissions

若要執行 DROP RULE,使用者至少必須有規則所屬結構描述的 ALTER 權限。To execute DROP RULE, at a minimum, a user must have ALTER permission on the schema to which the rule belongs.

範例Examples

下列範例會解除繫結再卸除名稱為 VendorID_rule 的規則。The following example unbinds and then drops the rule named VendorID_rule.

sp_unbindrule 'Production.ProductVendor.VendorID'  
DROP RULE VendorID_rule  
GO  

另請參閱See Also

CREATE RULE (Transact-SQL) CREATE RULE (Transact-SQL)
sp_bindrule (Transact-SQL) sp_bindrule (Transact-SQL)
sp_help (Transact-SQL) sp_help (Transact-SQL)
sp_helptext (Transact-SQL) sp_helptext (Transact-SQL)
sp_unbindrule (Transact-SQL) sp_unbindrule (Transact-SQL)
USE (Transact-SQL)USE (Transact-SQL)