Search of table names

前端 未结 9 1225
傲寒
傲寒 2021-01-29 22:10

I use the following to search for strings in my stored procedures:

use DBname
SELECT Name
FROM sys.procedures
WHERE OBJECT_DEFINITION(OBJECT_ID) LIKE \'%xxx%\'
<         


        
相关标签:
9条回答
  • 2021-01-29 22:44

    I'm using this and works fine

    SELECT * FROM INFORMATION_SCHEMA.TABLES 
    WHERE TABLE_NAME LIKE '%%'
    
    0 讨论(0)
  • 2021-01-29 22:44
    select name
      from DBname.sys.tables
     where name like '%xxx%'
       and is_ms_shipped = 0; -- << comment out if you really want to see them
    
    0 讨论(0)
  • 2021-01-29 22:45

    You can also use the Filter button to filter tables with a certain string in it. You can do the same with stored procedures and views.

    0 讨论(0)
  • 2021-01-29 22:58

    I know this is an old thread, but if you prefer case-insensitive searching:

    SELECT * FROM INFORMATION_SCHEMA.TABLES 
    WHERE Lower(TABLE_NAME) LIKE Lower('%%')
    
    0 讨论(0)
  • 2021-01-29 23:02

    I want to post a simple solution for every schema you've got. If you are using MySQL DB, you can simply get from your schema all the table's name and add the WHERE-LIKE condition on it. You also could do it with the usual command line as follows:

    SHOW TABLES WHERE tables_in_<your_shcema_name> LIKE '%<table_partial_name>%';
    

    where tables_in_<your_shcema_name> returns the column's name of SHOW TABLES command.

    0 讨论(0)
  • 2021-01-29 23:03

    I am assuming you want to pass the database name as a parameter and not just run:

    SELECT  *
    FROM    DBName.sys.tables
    WHERE   Name LIKE '%XXX%'
    

    If so, you could use dynamic SQL to add the dbname to the query:

    DECLARE @DBName NVARCHAR(200) = 'YourDBName',
            @TableName NVARCHAR(200) = 'SomeString';
    
    IF NOT EXISTS (SELECT 1 FROM master.sys.databases WHERE Name = @DBName)
        BEGIN
            PRINT 'DATABASE NOT FOUND';
            RETURN;
        END;
    
    DECLARE @SQL NVARCHAR(MAX) = '  SELECT  Name
                                    FROM    ' + QUOTENAME(@DBName) + '.sys.tables
                                    WHERE   Name LIKE ''%'' + @Table + ''%''';
    
    EXECUTE SP_EXECUTESQL @SQL, N'@Table NVARCHAR(200)', @TableName;
    
    0 讨论(0)
提交回复
热议问题