April 1, 2010 at 10:22 am
We have an old db with allot of columns/tables...having trouble finding columns
Is there a script I can run to find columns with the associated table name?
April 1, 2010 at 10:51 am
i use this a lot; it's ideal for finditng tablenames or column names that you are looking for.
stick in in the master db:
sp_find inv
finds all tables, and then all columns, which have "inv" in their name;
CREATE procedure [dbo].[sp_find]
@findcolumn varchar(50)
AS
BEGIN
SET NOCOUNT ON
--print object_name(@@PROCID)
SELECT
TableFound,
ColumnFound
FROM
(
SELECT
1 AS SortOrder,
sysobjects.name AS TableFound,
'' AS ColumnFound
FROM sysobjects
WHERE sysobjects.xtype IN('U' ,'V')
AND sysobjects.name LIKE '%' + @findcolumn + '%'
UNION ALL
SELECT
2 AS SortOrder,
sysobjects.name AS TableFound,
syscolumns.name AS ColumnFound
FROM sysobjects
INNER JOIN syscolumns ON sysobjects.id=syscolumns.id
WHERE sysobjects.xtype IN('U' ,'V')
AND syscolumns.name like '%' + @findcolumn + '%'
) X
ORDER BY
SortOrder,
TableFound,
ColumnFound
END
Lowell
April 1, 2010 at 7:35 pm
krypto69 (4/1/2010)
We have an old db with allot of columns/tables...having trouble finding columnsIs there a script I can run to find columns with the associated table name?
Just press the f4 key... you'll be amazed. It's a shame they didn't include the same functionality in 2k5.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply