Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Finding the tables that contain fieldX

Posted on 2000-05-04
5
Medium Priority
?
361 Views
Last Modified: 2008-02-20
I can check syscolumns to find how many tables contain a particular field in a database, but is there a way to pinpoint the tables those fields are in?
0
Comment
Question by:hemphandle
5 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 2776762
select o.name from sysobjects o join syscolumns c on o.id = c.id where c.Name = "id"

This returns the list of tables in the current database where column name is "id".
Is this what you are looking for?
0
 
LVL 5

Expert Comment

by:dtomyn
ID: 2777108
Perhaps better yet (if angelIII and I am following your question correctly) is to use INFORMATION_SCHEMA.COLUMNS
i.e.
SELECT TABLE_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_NAME = "id"
0
 

Accepted Solution

by:
USP earned 200 total points
ID: 2778219
You can also write the stored procedure which can accept the column name as parameter & generate the list of all the table like...

*--------------*
Create Procedure Sp_FindColumn
@MyCol varchar(255)
As
Select o.name As ResourceTable
From sysobjects o
Join syscolumns c
On o.id = c.id
Where c.Name = @mycol
*----------------*
0
 
LVL 5

Expert Comment

by:dtomyn
ID: 2778273
Gee thanks USP, your "Answer" is SO much better than mine and ESPECIALLY angelIII's!

Thanks again for adding your extreme insight on this one.  You really deserve those points!
0
 
LVL 4

Expert Comment

by:Gustavo Perez Buenrostro
ID: 2789206
hemphandle,
Check this one (Better and faster):

create proc spFindCol
@snColName sysname=null
as
begin
  set nocount on
  select object_name(id)
    from syscolumns
   where name=@snColName
end
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

927 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