Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8327769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:13:27+00:00 2026-06-09T01:13:27+00:00

I am merging a few tables and I need to query for specific column

  • 0

I am merging a few tables and I need to query for specific column names. Reason being these tables I am condensing have FK candidate columns but no FK so I would have to keep looking through every table to see if it contained a specific column name and that seems to be wearing on the eyes a little.

I got this from another post but it is not complete.

SELECT 'SELECT ''' + TABLE_NAME + '.' + column_name + 
   ''' FROM ' + TABLE_NAME + ' WHERE ' + 
   column_name + ' = ''[THE COLUMN NAME I AM LOOKING FOR]'''
FROM INFORMATION_SCHEMA.COLUMNS 

The TSQL above seems to not be structured correctly or I am missing something.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T01:13:28+00:00Added an answer on June 9, 2026 at 1:13 am

    This query will get a list of columns (along with their schema and table names) matching whatever you put into the parameter @SomeColumnName:

    DECLARE @SomeColumnName VarChar(200) = 'Test';
    
    SELECT S.name SchemaName, T.name TableName, C.name ColumnName
    FROM sys.columns C
         JOIN sys.tables T ON C.object_id = T.object_id
         JOIN sys.schemas S ON T.schema_id = S.schema_id
    WHERE C.name = @SomeColumnName;
    

    And if you are using a version of SQL Server that doesn’t have the newer DMVs, use this:

    SELECT *
    FROM INFORMATION_SCHEMA.COLUMNS C
    WHERE C.COLUMN_NAME = @SomeColumnName;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a few huge tables on a production SQL 2005 DB that need
I have written a Python script for merging many data files in a few
I've just finished merging two branches that have been separated for a long time,
I have a lot of pre-existing projects and code in a few different Subversion
Let's say I have two tables of similar structure, but one is empty and
There are a few ways to do a merge sort, but I specifically need
I have a painting application that is running out of memory on a few
Like merging errors, or rebase errors. Does it have a unique error code?
I did a few things wrong while merging trunk into a branch. First I
We have a few developers working on the same VS2005 solution, but our source

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.