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 VIDEOS
 
 
SQL E/BOOKS   WORLD, USA & SQL NEWS   FORMAT
SCRIPTS SQL 2005 SQL 2008 ARTICLES
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
SQL 2016 DESIGN & PROGRAMMING
 
 
 
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