Search code examples
sql-serverdatabasesql-server-2008t-sqlstored-procedures

Get the database name in which Stored Procedure exists


I am having SQL server 2008 and i am having 10 different databases in it and now i want to search one stored procedure that in which database the stored procedure is present.

Mentioned as duplicate by some ..... with out reading my question properly. My Requirement is i need to verify 'SP_Email' procedure. I which database is this procedure exists.


Solution

  • You can try this:

    EXEC sp_msforeachdb 
    'if exists(select 1 from [?].sys.objects where name=''SP_Email'')
    select ''?'' as FoundInDatabase from [?].sys.objects where name=''SP_Email'''