Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

SQL Server: need a list of tables with certain name

Posted on 2014-02-11
2
Medium Priority
?
478 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
2 Comments
 
LVL 23

Accepted Solution

by:
Steve Wales earned 750 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 750 total points
ID: 39851913
give this a try

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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

963 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