Parv The IT Geek

Join me on my Geeky Adventure

  • Home
  • About Me
  • Contact

Powered by Genesis

Find a column in a database with INFORMATION_SCHEMA.COLUMNS

29/01/2014 by Parvinder Nijjar Leave a Comment

Have you ever just been given a column name and not known which table it was in? Needed to check whether a column existed within a database?…

Well today I was just given a column name and told the information I needed was in there but alas they didn’t know which table it was in.

I could have gone through each table but that is very inefficient and I can more effectively harness the power of SQL to get the answer quickly and easily.

I knew that the INFORMATION_SCHEMA.COLUMNS would be a great place to start and did the below query.

SELECT *

FROM INFORMATION_SCHEMA.COLUMNS

1

 

The next step was to add the COLUMN_NAME in with a WHERE clause.

SELECT *

FROM INFORMATION_SCHEMA.COLUMNS

WHERE COLUMN_NAME = ‘max_history_rows’

2

Share this:

  • Click to print (Opens in new window)
  • Click to share on Facebook (Opens in new window)
  • Click to share on LinkedIn (Opens in new window)
  • Click to share on Reddit (Opens in new window)
  • Click to share on Twitter (Opens in new window)
  • Click to share on Tumblr (Opens in new window)
  • Click to share on Pinterest (Opens in new window)
  • Click to email this to a friend (Opens in new window)

Related

Filed Under: T-SQL Tagged With: Database Administration, Programming, Script

Leave a Reply Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Recent Posts

  • Quick introduction to SQL, databases and relational theory
  • My top tips for new programmers
  • Book Review: Learn Windows PowerShell in a Month of Lunches, Second Edition by Don Jones
  • Why you should learn programming
  • What would you like to learn or for me to talk about?

Categories

  • Analysis Services
  • C#
  • Database Engine
  • DMV
  • General
  • Integration Services
  • Personal Development
  • PowerShell
  • Replication
  • Reporting Services
  • T-SQL
  • Uncategorized

Tags

Attach database basics Business Intelligence C# Database Administration Database Design Database Engine DBCC CHECKDB DMV Export Data Intro Monthly Theme Personal Development PowerShell Programming Replication Script SSAS SSIS SSRS SSRS Administration T-SQL Windows Administration
loading Cancel
Post was not sent - check your email addresses!
Email check failed, please try again
Sorry, your blog cannot share posts by email.