December 20, 2010 at 3:04 pm
Hi.
I am using SQL Server 2005
I need to alter the certain query and to do this, I need to find other tables where certain column is used. I just joined the company and do not know the database structure yet, so I would like to see the tables where the column that I am interested in is used .. Basically I need to view all the tables where the column with certain name is present. I see filters of tables of certain name, etc.. however can't find how to filter by column name.
I know I used something like in Toad for Oracle ...
Can anyone help, please ...
December 20, 2010 at 3:28 pm
December 20, 2010 at 3:30 pm
I've enjoyed using Red Gate's free Search ad-in tool for questions like that. You can get it here:
http://www.red-gate.com/products/sql-development/sql-search/
The greatest enemy of knowledge is not ignorance, it is the illusion of knowledge. - Stephen Hawking
December 20, 2010 at 3:40 pm
Thanks ...
December 20, 2010 at 3:57 pm
Hi,
You can query from information schema view too, which provides the sql server metadata.
SELECT * FROM INFORMATION_SCHEMA.COLUMNS
WHERE column_name =''
This view provides both column name and tables names.
Thanks
John
December 20, 2010 at 5:11 pm
This will allow you to view specific columns by name, or by data type along with their associated table name.
SELECT so.Name AS 'Table',sc.Name AS 'Column'
FROM sys.sysobjects so
LEFT OUTER JOIN sys.syscolumns sc
ON sc.id = so.id
WHERE so.type = 'u'AND sc.name = 'EmployeeId' --using column name
--or use AND sc.xtype = 40 for all columns with a data type of Date
December 20, 2010 at 9:19 pm
bitbucket-25253 (12/20/2010)
This will allow you to view specific columns by name, or by data type along with their associated table name.
SELECT so.Name AS 'Table',sc.Name AS 'Column'
FROM sys.sysobjects so
LEFT OUTER JOIN sys.syscolumns sc
ON sc.id = so.id
WHERE so.type = 'u'AND sc.name = 'EmployeeId' --using column name
--or use AND sc.xtype = 40 for all columns with a data type of Date
Ron,
Eliminate the join... take a look at the OBJECT_NAME() function. It's a bit scope sensitive but so are both sys.objects and sys.sysobjects.
--Jeff Moden
Change is inevitable... Change for the better is not.
December 21, 2010 at 12:08 am
bitbucket-25253 (12/20/2010)
This will allow you to view specific columns by name, or by data type along with their associated table name.
SELECT so.Name AS 'Table',sc.Name AS 'Column'
FROM sys.sysobjects so
LEFT OUTER JOIN sys.syscolumns sc
ON sc.id = so.id
WHERE so.type = 'u'AND sc.name = 'EmployeeId' --using column name
--or use AND sc.xtype = 40 for all columns with a data type of Date
Both syscolumns and sysobjects are deprecated, should not be used in new development and will be removed in a future version of SQL server. They're there only for backward compat with SQL 2000. The replacements are sys.objects and sys.columns.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply