How to remove statistics from a SQL database so coredbutil.exe can upgrade the metaschema

Version 3

    If stats are enabled, it freezes the metaschema preventing Coredbutil.exe from being able to run successfully during upgrades. Stats has to be removed for successful metaschema updates.

     

    Verify that all of the tables in the LANDESK DB are owned by DBO. If they're not, change the ownership to DBO and then run the drop stats script:

     

    use (LANDESK Database Name Goes Here and remove parentheses)
    
    DECLARE @tblname sysname, @statname sysname, @sql nvarchar(2000)
    DECLARE c CURSOR FOR
    SELECT object_name(id), name FROM sysindexes WHERE INDEXPROPERTY(id, name, 'IsStatistics') = 1 and object_name(id) not like 'sys%'
    OPEN c
    FETCH NEXT FROM c INTO @tblname, @statname
    WHILE @@FETCH_STATUS = 0
    BEGIN
    SET @sql = 'DROP STATISTICS [' + @tblname + '].[' + @statname + ']'
    EXEC(@sql)
    FETCH NEXT FROM c INTO @tblname, @statname
    END
    CLOSE c
    DEALLOCATE c