Search of table names

前端 未结 9 1212
傲寒
傲寒 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 23:03

    you can also use the show command.

    show tables like '%tableName%'
    
    0 讨论(0)
  • 2021-01-29 23:04

    Adding on to @[RichardTheKiwi]'s answer.

    Whenever I search for a list of tables, in general I want to select from all of them or delete them. Below is a script that generates those scripts for you.

    The generated select script also adds a tableName column so you know what table you're looking at:

    select 'select ''' + name + ''' as TableName, * from ' + name as SelectTable,
    'delete from ' + name as DeleteTable
    from sys.tables
    where name like '%xxxx%'
    and is_ms_shipped = 0; 
    
    0 讨论(0)
  • 2021-01-29 23:08

    If you want to look in all tables in all Databases server-wide and get output you can make use of the undocumented sp_MSforeachdb procedure:

    sp_MSforeachdb 'SELECT "?" AS DB, * FROM [?].sys.tables WHERE name like ''%Table_Names%'''
    
    0 讨论(0)
提交回复
热议问题