Friday 31 May 2013

How to get all table name dependent on any column in SQl Server

Query for this is

SELECT o.Name as Table_Name , c.Name as Field_Name, t.Name as Data_Type
, t.length as Length_Size
FROM syscolumns c
     INNER JOIN sysobjects o ON o.id = c.id
     LEFT JOIN  systypes t on t.xtype = c.xtype 
WHERE o.type = 'U'  and c.name like '%country%'
ORDER BY o.Name, c.Name

here red color name is your required column name .

2 comments:

  1. Hi,nice sql query for getting all table name based on column in sql server

    Theosoft

    ReplyDelete
    Replies
    1. Hii hariharan
      Thanks for appricattion.
      you can also use another query

      SELECT * FROM sysobjects WHERE id IN ( SELECT id FROM syscolumns WHERE name like '%city%' )
      and type='u'

      where city is your column name (Tested in SQL server 2008)

      Delete