Find an object in SQL Server (cross-database)

后端 未结 10 1205
太阳男子
太阳男子 2021-02-01 16:52

If I\'ve been told a table (or proc) name, but not which connected database the object is located in, is there any simple script to search for it? Maybe search somewhere in the

10条回答
  •  旧时难觅i
    2021-02-01 17:53

    mayby one little change from the top answer, because DB_NAME() returns always content db of execution. so, for me better like below:

    sp_MSforeachdb 'select DB_name(db_id(''?'')) as DB, * From ?..sysobjects where xtype in (''U'', ''P'') And name like ''[_]x[_]%'''
    

    In my case I was looking for tables their names started with _x_

    Cheers, Ondrej

提交回复
热议问题