Sql server 在SQL Server Management Studio中,我可以跨多个数据库搜索资产吗?

Sql server 在SQL Server Management Studio中,我可以跨多个数据库搜索资产吗?,sql-server,ssms,Sql Server,Ssms,我的日常IDE是Eclipse,它有一个极好的开放资源特性(CTRL+SHIFT+R或Navigate>OpenResource),允许用户在多个项目中搜索文件/资源 我在SQL Server Management Studio中找不到类似的功能,有吗?我希望有人能比我更好地回答这个问题。过去,我使用光标搜索所有数据库,并将结果插入临时表。然后我可以从临时表中选择并显示结果 我再也没有这种代码了。如果没有人能想出更好的答案,我会回来用一些真实的代码编辑这个。我想会有一辆车管所。有人吗?没有。SM

我的日常IDE是Eclipse,它有一个极好的开放资源特性(CTRL+SHIFT+R或Navigate>OpenResource),允许用户在多个项目中搜索文件/资源


我在SQL Server Management Studio中找不到类似的功能,有吗?

我希望有人能比我更好地回答这个问题。过去,我使用光标搜索所有数据库,并将结果插入临时表。然后我可以从临时表中选择并显示结果


我再也没有这种代码了。如果没有人能想出更好的答案,我会回来用一些真实的代码编辑这个。我想会有一辆车管所。有人吗?

没有。SMS中没有能够跨项目搜索的默认机制。

您可以使用信息架构视图在sql数据库中搜索对象 有一个用于表、列、函数、存储过程等

从信息_SCHEMA.routines中选择*
在例程定义如“%xp%”

中,您可以像这样使用sp\u MSforeachdb:

sp_MSforeachdb 'SELECT * FROM ?.INFORMATION_SCHEMA.routines WHERE ROUTINE_TYPE = ''PROCEDURE'''

上面将选择所有数据库中的所有过程,并在不同的结果集中返回它们。使用不同的视图,您还可以选择表、列等。

我相信这就是您要寻找的:

它是完全免费的,而且非常棒


(来源:)


我使用以下CLR存储过程以显式并行方式搜索数据库中的所有表和列。也许它是你想要的。它不搜索存储的进程或函数,但可以查找值、列名、表名等,并以XML行的形式返回结果。请注意,这不应该在日常工作中使用,但它对于偶尔的审计或取证/DBA任务非常有用,而且它绝对是快速的。。。搜索AdventureWorks上的所有表格,只需2秒钟时间,只需安装在一台普通的台式PC上


你的意思是,就像在数据库中的所有表中搜索列名一样?你使用的是什么版本的SQL Server?我使用的是SQL Server 2005,我考虑的是存储过程、表、视图等。但是列也很好+我不敢相信这不是公认的答案。伟大的工具!谢谢
/*
    This script creates a CLR stored procedure and its assembly on a database that will let you search for
    keywords separated by a space on all columns of all tables of all types except 'binary', 'varbinary', 'bit',
    'timestamp', 'image', 'sql_variant', and 'hierarchyid'. This was made as a CLR stored proc to take advantage
    of explicit parallelism to make the search a lot faster. Be aware that this will use many cores so only use
    this for occasional DBA work. This has the potential to cause a DDoS type of situation if broad searches with
    many results are hammered into the server, since each request can try to parallelize its search. An optional
    parameter exists to limit parallelism to a set number of cores. You can also set filters on the tables or
    columns to search, including logical operators OR, AND, NOT, and parenthesis (see examples below). Results
    are returned as XML rows.

    To install you need owner rights. Also, because SQL Server doesn't allow secondary CLR threads access to 
    the stored procedure context, we extract the connection string from the first context connection we make.
    This works fine, but only if you are connected with a trusted connection (using a Windows account).

    ------------------------------------------------------------------
    -- CLR access must be enabled on the instance for this to work. --
    ------------------------------------------------------------------
    -- sp_configure 'show advanced options', 1;                     --
    -- GO                                                           --
    -- RECONFIGURE;                                                 --
    -- GO                                                           --
    -- sp_configure 'clr enabled', 1;                               --
    -- GO                                                           --
    -- RECONFIGURE;                                                 --
    -- GO                                                           --
    ------------------------------------------------------------------

    -----------------------------------------------------------------------------------
    -- Database needs to be flagged trustworthy to be able to access CLR assemblies. --
    -----------------------------------------------------------------------------------
    -- ALTER DATABASE [AdventureWorks] SET TRUSTWORTHY ON;                           --
    -----------------------------------------------------------------------------------

    Example usages:
    ---------------
    Using all available processors on the server:
        EXEC [dbo].[SearchAllTables] @valueSearchTerm = 'john michael'

    Limiting the server to 4 concurrent threads:
        EXEC [dbo].[SearchAllTables] @valueSearchTerm = 'john michael', @maxDegreeOfParallelism = 4

    Using logical operators in search terms:
        EXEC [dbo].[SearchAllTables] @valueSearchTerm = '(john or michael) and not jack', @tablesSearchTerm = 'not contact'

    Limiting search to table names and/or column names containing some search terms:
        EXEC [dbo].[SearchAllTables] @valueSearchTerm = 'john michael', @tablesSearchTerm = 'person contact', @columnsSearchTerm = 'address name'

    Limiting search results to the first row of each table where the terms are found:
        EXEC [dbo].[SearchAllTables] @valueSearchTerm = 'john michael', @getOnlyFirstRowPerTable = 1

    Limiting the search to the schema only automatically returns only the first row for each table:
        EXEC [dbo].[SearchAllTables] @tablesSearchTerm = 'person contact'

    Only return the search queries:
        EXEC [dbo].[SearchAllTables] @valueSearchTerm = 'john michael', @tablesSearchTerm = 'person contact', @onlyOutputQueries = 1

    Capturing results into temporary table and sorting:
        CREATE TABLE #temp (Result NVARCHAR(MAX));
        INSERT INTO #temp
            EXEC [dbo].[SearchAllTables] @valueSearchTerm = 'john';
        SELECT * FROM #temp ORDER BY Result ASC;
        DROP TABLE #temp;
*/