5

我的日常 IDE 是 Eclipse,它具有出色的开放资源功能(CTRL+SHIFT+R 或 Navigate > Open Resource),允许用户跨多个项目搜索文件/资源​​。

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

4

6 回答 6

9

我相信这就是你要找的东西: http ://www.red-gate.com/products/sql-development/sql-search/

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

在此处输入图像描述
(来源:red-gate.com

在此处输入图像描述

于 2012-07-31T21:33:30.883 回答
3

您可以使用信息架构视图在 sql 数据库中搜索对象 http://msdn.microsoft.com/en-us/library/ms186778.aspx 有一个用于表、列、函数、存储过程等。

select * from INFORMATION_SCHEMA.routines where ROUTINE_DEFINITION like '%xp%_'

于 2008-10-07T17:06:19.923 回答
1

不,SMS 中没有默认机制可以跨项目进行搜索。

于 2008-10-03T11:24:21.730 回答
1

您可以像这样使用 sp_MSforeachdb:

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

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

于 2008-10-24T17:28:44.697 回答
0

我希望有人比我有更好的答案。过去,我使用 CURSOR 搜索所有数据库并将结果插入临时表。然后我可以从临时表中选择并显示结果。

我没有这个代码了。如果没有人想出更好的答案,我会回来用一些真实的代码编辑它。我认为会有一个DMV。任何人?

于 2008-09-29T15:16:17.523 回答
0

我制作了以下 CLR 存储过程来搜索具有显式并行性的数据库中的所有表和所有列。也许它会做你想要的。它不搜索存储的过程或函数,但您可以查找值、列名、表名等,并以 XML 行的形式返回结果。请注意,这不应该在日常使用,但它对于偶尔的审计或取证/DBA 任务很有用,而且它绝对很快......在 2 秒内搜索 AdventureWorks 上的所有表,平板托管在一台普通的台式 PC 上。

https://pastebin.com/RRTrt8ZN

/*
    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;
*/
于 2019-08-22T21:27:08.337 回答