• Hugo Kornelis (2/6/2016)


    Ed Wagner (2/5/2016)


    The ms_foreachdb uses a cursor to iterate through the databases on the instance. If you have to cursor through only a few databases, why not write your own cursor to define which ones to process? Then you won't have to worry about running through all of them or the occasional miss that happens every so often with ms_foreachdb.

    Make sure to declare that cursor either STATIC or FAST_FORWARD. Not using those options is exactly the reason why sp_msforeachdb occassionally fails.

    Sure enough. When using a cursor is a necessity, it's fast forward and read only. At least it minimizes the impact of having to use one.