Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

find sql table name with a particular column

Tags:

sql

sql-server

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' 
like image 961
RobertKing Avatar asked Aug 13 '13 14:08

RobertKing


People also ask

How do I find the table name for a particular column?

USE YourDatabseName GO 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.

Can I search a SQL database for a column name?

A feature that can be used to search for column names in SQL Server is Object search. This feature allows users to find all SQL objects containing the specified phrase.


1 Answers

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.

like image 167
Damien_The_Unbeliever Avatar answered Sep 29 '22 15:09

Damien_The_Unbeliever