Syntax of ms_foreachdb?

  • Does anyone have an example of using the sp ms_foreachdb? I know what it does, I just can't remember the syntax.

    TIA,

    Bobby

  • sp_msforeachdb 'use ?;insert into server.db.dbo.database_files_FOR_BKUP exec sp_helpfile'

    GO



    Michelle

  • FOR SQL Server version 6.5

    You will need to create a TEMP table as follows and execute sp_MSDBUserProfile proc.

    Create Table #SQLOLEDbUserProfile (dbid int NOT NULL PRIMARY KEY,

    profilebits int NOT NULL)

    Exec Master..sp_MSDBUserProfile 'init'

    Exec sp_msforeachdb 'Use ? Select db_id(), ''?'' '

    For vesrsions 7.0 and greater you can simply exec. the proc as follows

    Exec sp_msforeachdb 'Use ? Select db_id(), ''?'' ' OR

    Exec sp_msforeachdb 'Use ? Select * From Authors Where au_id is not null'

    MW


    MW

  • Thanks to all who responded.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply