DROP STATISTICS (Transact-SQL)DROP STATISTICS (Transact-SQL)

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

卸除目前資料庫中指定資料表內多個集合的統計資料。Drops statistics for multiple collections within the specified tables in the current database.

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

語法Syntax

-- Syntax for SQL Server and Azure SQL Database  
  
DROP STATISTICS table.statistics_name | view.statistics_name [ ,...n ]  
-- Syntax for Azure SQL Data Warehouse and Parallel Data Warehouse  
  
DROP STATISTICS [ schema_name . ] table_name.statistics_name   
[;]  

引數Arguments

table | viewtable | view
這是應該卸除統計資料之目標資料表或索引檢視的名稱。Is the name of the target table or indexed view for which statistics should be dropped. 資料表和檢視名稱必須符合資料庫識別碼的規則。Table and view names must comply with the rules for Database Identifiers. 資料表或檢視擁有者名稱的指定是選擇性的。Specifying the table or view owner name is optional.

statistics_namestatistics_name
這是要卸除的統計資料群組名稱。Is the name of the statistics group to drop. 統計資料名稱必須符合識別碼的規則。Statistics names must comply with the rules for identifiers

RemarksRemarks

當您卸除統計資料時,請小心。Be careful when you drop statistics. 執行這個動作,可能會影響查詢最佳化工具所選擇的執行計畫。Doing so may affect the execution plan chosen by the query optimizer.

索引的統計資料無法利用 DROP STATISTICS 來卸除。Statistics on indexes cannot be dropped by using DROP STATISTICS. 只要索引存在,就會保留統計資料。Statistics remain as long as the index exists.

如需顯示統計資料的詳細資訊,請參閱 DBCC SHOW_STATISTICS (Transact-SQL)For more information about displaying statistics, see DBCC SHOW_STATISTICS (Transact-SQL).

權限Permissions

需要資料表或檢視表的 ALTER 權限。Requires ALTER permission on the table or view.

範例Examples

A.A. 從資料表卸除統計資料Dropping statistics from a table

下列範例會卸除兩份資料表的統計資料群組 (集合)。The following example drops the statistics groups (collections) of two tables. VendorCredit 資料表的 Vendor 統計資料群組 (集合) 和 CustomerTotal 資料表的 SalesOrderHeader 統計資料 (集合) 都會卸除。The VendorCredit statistics group (collection) of the Vendor table and the CustomerTotal statistics (collection) of the SalesOrderHeader table are dropped.

-- Create the statistics groups.  
USE AdventureWorks2012;  
GO  
CREATE STATISTICS VendorCredit  
    ON Purchasing.Vendor (Name, CreditRating)  
    WITH SAMPLE 50 PERCENT  
CREATE STATISTICS CustomerTotal  
    ON Sales.SalesOrderHeader (CustomerID, TotalDue)  
    WITH FULLSCAN;  
GO  
DROP STATISTICS Purchasing.Vendor.VendorCredit, Sales.SalesOrderHeader.CustomerTotal;  
  

範例:Azure Synapse Analytics (SQL DW)Azure Synapse Analytics (SQL DW)平行處理資料倉儲Parallel Data WarehouseExamples: Azure Synapse Analytics (SQL DW)Azure Synapse Analytics (SQL DW) and 平行處理資料倉儲Parallel Data Warehouse

B.B. 從資料表卸除統計資料Dropping statistics from a table

下列範例會從資料表 Customer 卸除 CustomerStats1 統計資料。The following examples drop the CustomerStats1 statistics from table Customer.

DROP STATISTICS Customer.CustomerStats1;  
DROP STATISTICS dbo.Customer.CustomerStats1;  
  

另請參閱See Also

ALTER DATABASE (Transact-SQL) ALTER DATABASE (Transact-SQL)
CREATE INDEX (Transact-SQL) CREATE INDEX (Transact-SQL)
CREATE STATISTICS (Transact-SQL) CREATE STATISTICS (Transact-SQL)
sys.stats (Transact-SQL) sys.stats (Transact-SQL)
sys.stats_columns (Transact-SQL) sys.stats_columns (Transact-SQL)
DBCC SHOW_STATISTICS (Transact-SQL) DBCC SHOW_STATISTICS (Transact-SQL)
sp_autostats (Transact-SQL) sp_autostats (Transact-SQL)
sp_createstats (Transact-SQL) sp_createstats (Transact-SQL)
UPDATE STATISTICS (Transact-SQL) UPDATE STATISTICS (Transact-SQL)
EVENTDATA (Transact-SQL) EVENTDATA (Transact-SQL)
USE (Transact-SQL)USE (Transact-SQL)