Wednesday, March 28, 2012

how to enumerate all table in db??

how to enumerate all table with a column name in sqlserver db?This returns all objects with a given column name:

--------------
declare @.SearchColumn varchar(50)
set @.SearchColumn = 'Database_ID'

select sysobjects.name as ObjectName,
sysobjects.xtype as ObjectType
from sysobjects
inner join syscolumns on sysobjects.id = syscolumns.id
where syscolumns.name = @.SearchColumn
--------------

If you want just tables, filter for sysobjects.xtype = 'U'

No comments:

Post a Comment