17 October,2007 by Tom Collins
Use this script to delete all statistics from a given table in SQL 2005.
/****************************************************************** File Name : delete-statistics-from-table.sql -- Author : Jack Vamvas -- Description :Delete statistics from table -- Last Modified:17/10/2007 ******************************************************************/ DECLARE @db_Table VARCHAR(200) SET @db_Table = 'MyTable' DECLARE TableStats CURSOR FOR SELECT Name FROM sys.stats WHERE object_id = object_id(@db_Table) AND auto_created <> 0 DECLARE @StatName NVARCHAR(512) OPEN TableStats FETCH next FROM TableStats INTO @StatName WHILE @@FETCH_STATUS = 0 BEGIN EXEC ('drop statistics '+@db_table+'.' + @StatName) FETCH NEXT FROM TableStats INTO @StatName END CLOSE TableStats DEALLOCATE TableStats GO
SQL Server sp_updatestats and UPDATE STATISTICS
This is only a preview. Your comment has not yet been posted.
As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.
Having trouble reading this image? View an alternate.
Posted by: |