Mats codemix

Mats codemix

A little c#, a litte .NET and throw in some c++ and you get a nice Spaghetti

Mats codemix RSS Feed
 
 
 
 

SQL - Show tables containing a column

When digging through database tables i use this little select-sctatement to find out which tables that contain a scertain column name.

 1 -- Show tables containing a column
 2 select sysobj.name + '.' + syscol.name
 3 , 'sp_help ' + sysobj.name as sptext
 4 , 'select * from ' + sysobj.name as selall
 5 , 'select count(*) from ' + sysobj.name as selcount
 6 from sysobjects sysobj, syscolumns syscol
 7 where sysobj.id = syscol.id
 8 and syscol.name
 9 like '%somecolumnamer%'
10 and sysobj.name not like 'RPT%'
11 and sysobj.name like '%[_]T'
12 order by syscol.name,sysobj.name

Works on Sybase 12 and probably on MS SqlServer too.

Maybe you have another tip on finding relations between tables using SQL?

Leave a Reply