Solved

SQL Server: need a list of tables with certain name

Posted on 2014-02-11
2
467 Views
Last Modified: 2014-02-26
Hi, what is the best way to get a list of tables with name like '%name1%' from all server instance databases?
Thanks.
0
Comment
Question by:quasar_ee
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 22

Accepted Solution

by:
Steve Wales earned 250 total points
ID: 39851900
May not be the most elegant way to do it but for a quick and dirty use the undocumented procedure sp_MSForEachDB:

EXEC dbo.sp_MSforeachdb 'USE [?];  IF EXISTS (SELECT * FROM  sys.tables WHERE name like ''%name1%'' ) select ''Table ''+name+'' exists in database ''+DB_NAME() from sys.tables where name like ''%name1%''';

Open in new window

0
 
LVL 5

Assisted Solution

by:dannygonzalez09
dannygonzalez09 earned 250 total points
ID: 39851913
give this a try

sp_msforeachdb 'select "?" AS db, * from [?].sys.tables where name like ''%name1%'''
0

Featured Post

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question