34

Is their any other way or sql query to find the database table names with a particular column than shown below,

SELECT TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME = 'NameID'
8
  • 3
    Why would you need another way? Commented Aug 13, 2013 at 14:21
  • 1
    That's the way if you want to use standards SQL. If you don't, then you need to add a tag for your specific RDBMS product (e.g. Oracle, MySQL, etc) Commented Aug 13, 2013 at 14:21
  • this might differ depending on the RDBMS you are using. Commented Aug 13, 2013 at 14:21
  • watch out querying INFORMATION_SCHEMA should be very heavy for your server. Commented Aug 13, 2013 at 14:27
  • that's why i was asking for another approach.. Commented Aug 13, 2013 at 15:24

3 Answers 3

32

In SQL Server, you can query sys.columns.

Something like:

 SELECT
     t.name
 FROM
     sys.columns c
        inner join
     sys.tables t
        on
           c.object_id = t.object_id
 WHERE
     c.name = 'NameID'

You might want an additional lookup to resolve the schema name, if you have tables in multiple schemas.

Sign up to request clarification or add additional context in comments.

Comments

7

you can run this query

SELECT t.name AS table_name,
SCHEMA_NAME(schema_id) AS schema_name,
c.name AS column_name
FROM sys.tables AS t
INNER JOIN sys.columns c ON t.OBJECT_ID = c.OBJECT_ID
WHERE c.name LIKE '%Column%' -- write the column you search here
ORDER BY schema_name, table_name;

Comments

0

For Oracle Database. Use the below query:

select table_name from all_tab_columns where column_name = 'NameID';

If you’ve got DBA privileges, you can try this command instead:

select table_name from dba_tab_columns where column_name = 'NameID';

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.