Solved

How can I find a table in SQL server 2016

Posted on 2016-10-18
4
53 Views
Last Modified: 2016-10-18
How can I find a table in SQL server 2016.
I could use this to find the table in the current database:
SELECT *
FROM sys.Tables
WHERE name LIKE '%Application_Current_Sequence_Number%'


The problem is, I have several databases on the server.

Kindly help.
0
Comment
Question by:Olugbnega Oyeneye
  • 2
  • 2
4 Comments
 
LVL 46

Accepted Solution

by:
Vitor Montalvão earned 500 total points
ID: 41848019
So you want to find a table but you don't know in each database is it?
If so then use sp_MSforeachdb and run the following:
USE Master
GO
EXEC sp_MSforeachdb
@command1='use ?; SELECT *
 FROM sys.Tables
 WHERE name LIKE ''%Application_Current_Sequence_Number%'''

Open in new window

0
 

Author Comment

by:Olugbnega Oyeneye
ID: 41848022
I got this error message:

Msg 208, Level 16, State 1, Line 3
Invalid object name 'sys.Tables'.
0
 
LVL 46

Expert Comment

by:Vitor Montalvão
ID: 41848053
Are you running in a SQL Server 2016 instance, right?
Is that instance Case Sensitive? If so, then write sys.tables in lower case:
USE Master
GO
EXEC sp_MSforeachdb
@command1='use ?; SELECT *
 FROM sys.tables
 WHERE name LIKE ''%Application_Current_Sequence_Number%'''

Open in new window

0
 

Author Closing Comment

by:Olugbnega Oyeneye
ID: 41848058
It works.
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Via a live example, show how to shrink a transaction log file down to a reasonable size.

867 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now