Solved

find all columns in a database with name like...

Posted on 2016-10-12
4
43 Views
Last Modified: 2016-11-03
Hey guys-
is there a way to query a whole database and find all the columns (regardless of what table it lies in)
that has a name like optionskey?
0
Comment
Question by:jamesmetcalf74
  • 2
4 Comments
 
LVL 69

Accepted Solution

by:
Scott Pletcher earned 250 total points
ID: 41840904
Something like this:

SELECT ...
FROM sys.columns c
INNER JOIN sys.tables t ON t.object_id = c.object_id
WHERE name LIKE '%option%key%' /*adjust as needed to get specifically what you want*//
0
 
LVL 65

Assisted Solution

by:Jim Horn
Jim Horn earned 250 total points
ID: 41840905
Sure..
SELECT t.name as table_name, c.name as column_name
FROM sys.tables t
   JOIN sys.columns c ON t.object_id = c.object_id
WHERE c.name LIKE '%optionskey%'

Open in new window

0
 
LVL 69

Expert Comment

by:Scott Pletcher
ID: 41840910
Correction:

WHERE name ...

Should be:

WHERE c.name ...
0
 

Author Comment

by:jamesmetcalf74
ID: 41850166
Thanks you guys.
sorry for the late response.
you got me squared away
0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
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.

829 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