July 11, 2009 at 12:20 pm
I have forgotten how to search for a column name through a certain DB.
For instance I need to find all columns that have *title* in the name and the name of the tables that have them.
Any help is appreciated
July 11, 2009 at 12:55 pm
here is a simple procedure i use all the time;
stick in the master database, and because it starts with "sp_" and uses the catibility views, it will be functional in all databases.
so simple to use: sp_find title
create procedure sp_find
@findcolumn varchar(50)
as
begin
set nocount on
select
sysobjects.name as TableFound,
syscolumns.name as ColumnFound
from sysobjects
inner join syscolumns on sysobjects.id=syscolumns.id
where syscolumns.name like '%' + @findcolumn +'%'
or sysobjects.name like '%' + @findcolumn +'%'
order by sysobjects.name
end
Lowell
July 11, 2009 at 1:06 pm
Thanks Lowell!
July 11, 2009 at 6:59 pm
Lowell (7/11/2009)
here is a simple procedure i use all the time;stick in the master database, and because it starts with "sp_" and uses the catibility views, it will be functional in all databases.
so simple to use: sp_find title
or, updated for 2005...
create procedure sp_find
@findcolumn varchar(50)
as
begin
set nocount on
select
sys.Tables.name as TableFound,
sys.Columns.name as ColumnFound
from sys.Tables
inner join sys.Columns on sys.Tables.object_id=sys.Columns.object_id
where sys.columns.name like '%' + @findcolumn +'%'
or sys.Tables.name like '%' + @findcolumn +'%'
order by sys.Tables.name
end
Nice code Lowell.
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply