Solved

Query to find a specific field ina a single databse

Posted on 2006-07-05
9
421 Views
Last Modified: 2008-01-09
I am in need of a solution to find a specific field, and how many times it is used, referenced throughout a databse

There are 2064 tables in databse A - I want to find out which tables have the 'company' field in this database.  Is there a query that can be written to find all of the tables that use 'company' as a field in databse A.  I do not care what the data is at this time, just want to know the location of the field without having to query each table.

Thank you in advance for your assistance.

Greg

0
Comment
Question by:Okie13
[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
9 Comments
 
LVL 12

Accepted Solution

by:
Einstine98 earned 225 total points
ID: 17046692
use sysobjects to find the tables
sysdepends to find dependencies
syscolumns to locate a specific column

example

SELET O.Name
FROM sysobjects AS O
JOIN syscolumns AS C
on C.id = O.ID
WHERE C.Name = 'company'
0
 
LVL 42

Assisted Solution

by:Eugene Z
Eugene Z earned 200 total points
ID: 17047574
try:
INFORMATION_SCHEMA.COLUMNs view: http://msdn2.microsoft.com/en-us/library/ms188348.aspx

exec master..sp_msforeachdb 'use ? select * from INFORMATION_SCHEMA.COLUMNs where column_name=''company'''
++++++++++++++++++++++++=
or\and
undocumented solution:

exec master.dbo.sp_MSobjsearch @searchkey = N'company', @objecttype = 1024, @dbname = [*], @casesensitive = 0, @hitlimit = 1000, @status = 1, @extpropname = NULL, @extpropvalue = NULL
0
 
LVL 42

Assisted Solution

by:Eugene Z
Eugene Z earned 200 total points
ID: 17047581
also there is GUI solution:
open Query Analyzer and press F4 (find object)...
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
LVL 42

Expert Comment

by:Eugene Z
ID: 17047585
BTW:
the solution for all databases:
exec master..sp_msforeachdb 'use ? select * from INFORMATION_SCHEMA.COLUMNs where column_name=''company'''

you need just:
use yourDBname
select * from INFORMATION_SCHEMA.COLUMNs where column_name='company'
0
 
LVL 75

Assisted Solution

by:Aneesh Retnakaran
Aneesh Retnakaran earned 75 total points
ID: 17047706
SELECT DISTINCT TABLE_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_NAME = 'Company'
0
 
LVL 42

Expert Comment

by:Eugene Z
ID: 17049446
aneeshattingal:
 why do you need "DISTINCT"? How many COLUMN_NAME = 'Company' can be per table?
It is just and One. No need in 'SELECT DISTINCT TABLE_NAME ...'
                                                   --------^----------
0
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 17049577
You are right EugeneZ...
"DISTICT" is not really needed in that.. Also I didn't See your previous post ... .
0
 
LVL 35

Expert Comment

by:James0628
ID: 17049671
You can find a stored procedure named sp_FindColumn at the following URL.  It will let you search for one or more columns by name or partial name, and some other options.

 http://searchsqlserver.techtarget.com/tip/1,289483,sid87_gci1109458,00.html

 James
0
 

Author Comment

by:Okie13
ID: 17050707
Thanks to all of you - each your answers worked perfectly and really helped me out - I gave the most to Einstine98 for being first ... EugeneZ:  Thanks for the GUI tip - I liked that ome since I am in it so often.

As I said all of the answers worked and I really do appreciate it!!

Greg
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

Suggested Solutions

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…
I have a large data set and a SSIS package. How can I load this file in multi threading?
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

756 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