Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to find field exists in which table +sql server

Posted on 2011-03-11
4
Medium Priority
?
667 Views
Last Modified: 2012-05-11
Hi,
I know the field exists in databse but,need to know in which table.
Any suggestions are appreciated.

Cheers
0
Comment
Question by:RIAS
  • 2
4 Comments
 
LVL 9

Assisted Solution

by:mayank_joshi
mayank_joshi earned 1000 total points
ID: 35107447
this will dispaly the table name in which the column exists:-

select OBJECT_NAME(object_id) from sys.columns where name='your_column_name'

Open in new window

0
 
LVL 24

Accepted Solution

by:
jimyX earned 1000 total points
ID: 35107451
Use IF EXISTS as follows:
if exists (select TheColumnName from INFORMATION_SCHEMA.Columns where Table_Name = 'YourTable')
0
 

Author Closing Comment

by:RIAS
ID: 35107457
Cheers mates!!!
0
 
LVL 9

Expert Comment

by:mayank_joshi
ID: 35107462
alternative way :-

select TABLE_NAME from INFORMATION_SCHEMA.COLUMNS where COLUMN_NAME='your_column_name'

Open in new window

0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing XML code a very difficult part is when we like to remove all the elements or attributes from the XML that have no data. I would like to share a set of recursive MSSQL stored procedures that I have made to remove those elements from …
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Screencast - Getting to Know the Pipeline

877 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question