Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • SQL : How to find all tables containing column with specific name ?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 299
    Comment on it

    Many times we come across a requirement of finding names of all tables which contain specific columns. We can get the answer by using the below query:

    SELECT COL.name AS ColumnName, TAB.name AS TableName
    FROM sys.columns COL
        JOIN sys.tables TAB ON COL.object_id = TAB.object_id
    WHERE COL.name LIKE '%ColumnNameToSearch%'
    

    For example ,if we want to find names of table containing column by the name employee. The corresponding query will be as below:

    SELECT COL.name AS ColumnName, TAB.name AS TableName
    FROM sys.columns COL
        JOIN sys.tables TAB ON COL.object_id = TAB.object_id
    WHERE COL.name LIKE '%employee%'
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: