Thursday, May 3, 2012

Remove Hypothetical Indexes Generated by SQL DTA

Here is the sql statement to generate the scripts to drop hypothetical indexes that were generated by SQL Database Engine Tunning Advisor (DTA).


SELECT 'DROP INDEX [' + s.[name] + '] ON [' + object_name(s.[object_id]) +'] '
FROM sys.stats AS s
INNER JOIN sys.indexes AS i
    ON s.name=i.name
WHERE i.is_hypothetical=1 and s.[name] LIKE '_dta_ind%'


SELECT 'DROP STATISTICS  [' + object_name(s.[object_id]) + '].[' + s.[name] + '] '
FROM sys.stats AS s
WHERE s.name like '_dta_stat%'

1 comment: