Solved

How can I find a table in SQL server 2016

Posted on 2016-10-18
4
41 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 45

Accepted Solution

by:
Vitor Montalvão earned 500 total points
Comment Utility
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
Comment Utility
I got this error message:

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

Expert Comment

by:Vitor Montalvão
Comment Utility
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
Comment Utility
It works.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Read about achieving the basic levels of HRIS security in the workplace.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
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 to return specific rows and columns, with various degrees of sorting and limits in place.

763 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

6 Experts available now in Live!

Get 1:1 Help Now