?
Solved

Query to find a specific field ina a single databse

Posted on 2006-07-05
9
Medium Priority
?
433 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 900 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 43

Assisted Solution

by:Eugene Z
Eugene Z earned 800 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 43

Assisted Solution

by:Eugene Z
Eugene Z earned 800 total points
ID: 17047581
also there is GUI solution:
open Query Analyzer and press F4 (find object)...
0
10 Questions to Ask when Buying Backup Software

Choosing the right backup solution for your organization can be a daunting task. To make the selection process easier, ask solution providers these 10 key questions.

 
LVL 43

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 300 total points
ID: 17047706
SELECT DISTINCT TABLE_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_NAME = 'Company'
0
 
LVL 43

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

Does Your Cloud Backup Use Blockchain Technology?

Blockchain technology has already revolutionized finance thanks to Bitcoin. Now it's disrupting other areas, including the realm of data protection. Learn how blockchain is now being used to authenticate backup files and keep them safe from hackers.

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.
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Suggested Courses

800 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