DATETIME SELECT SELECT INTO DATE PAD STRING DYNAMIC SQL CURSOR MONEY FORMAT PERCENT STORED PROCEDURE SQL SERVER AGENT JOB OPTIMIZATION WHILE LOOP OVER PARTITION BY UPDATE
SITE SEARCH SQLUSA.com HEADLINES NEWS
SQL E/BOOKS   SQL 2014 PROGRAMMING   DOWNLOADS
SCRIPTS SQL 2005 SQL 2008 ARTICLES
SQL JOBS TWITTER FORMAT VIDEOS
How to drop all stats on a table?

Execute the following Microsoft SQL Server T-SQL scripts in SSMS Query Editor to drop all stats on the Sales.SalesOrderDetail table.

-- SQL drop statistics - drop all stats on a table

-- SQL Server drop statistics - T-SQL cursor

USE AdventureWorks2008

GO

DECLARE curAllStats CURSOR  FOR

SELECT Name

FROM   sys.stats

WHERE  object_id = object_id('Sales.SalesOrderDetail')

       AND auto_created <> 0

 

DECLARE  @StatName NVARCHAR(512)

 

OPEN curAllStats

 

FETCH NEXT FROM curAllStats

INTO @StatName

 

WHILE @@FETCH_STATUS = 0

  BEGIN

    EXEC( 'drop statistics Sales.SalesOrderDetail.' + @StatName)

    

    FETCH NEXT FROM curAllStats

    INTO @StatName

  END -- WHILE

 

CLOSE curAllStats

 

DEALLOCATE curAllStats

GO

------------

 

-- T-SQL DBCC SHOW_STATISTICS - display statistics

DBCC SHOW_STATISTICS ("Sales.SalesOrderDetail", AK_SalesOrderDetail_rowguid);

------------

 

Exam Prep 70-461
Exam 70-461
DATETIME SELECT SELECT INTO DATE PAD STRING DYNAMIC SQL CURSOR MONEY FORMAT PERCENT STORED PROCEDURE SQL SERVER AGENT JOB OPTIMIZATION WHILE LOOP OVER PARTITION BY UPDATE