• Sue_H - Monday, January 8, 2018 3:02 PM

    One problem with the script is that it is hard coded to use db_id 70 when using this:
    sys.dm_db_index_physical_stats (70, NULL, NULL, NULL, NULL) AS p

    Maybe change that to Default, null or 0 instead of 70

    Sue

    DB_ID() would probably be more efficient, since dm_db_index_usage_stats is scoped to the current DB.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass