Postgresql how do i find a table based on column name? - sql

I know that I have a table with the column "fortyid" but I cant remember which table it is and I have like 350 tables in my database.
Is there a way to find all tables that has "fortyid" as column? (doesn't matter the type)

You can use the metadata defined by the SQL standard, specifically INFORMATION_SCHEMA.COLUMNS.
select c.*
from information_schema.columns c
where c.column_name = 'fortyid';

Related

Searching all tables in database containing specific column

I am looking for a simple query to find all tables within a database that have a certain "id" column, confusing myself as not all the tables contain this "id"
Using INFORMATION_SCHEMA.COLUMNS:
SELECT *
FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_NAME = 'id'

Is there a way to get all column names in a table for IBM Netezza? [duplicate]

Is there a query I can write to search all the column names for a particular database in Netezza?
Within the same database you can use the following query:
select *
from _v_odbc_columns1
where column_name like '%columnname%'
or a less Netezza specific query
select *
from information_schema.columns
where column_name like '%columnname%'
The important catalog views in netezza system are listed below
_V_USER: the user view gives information about the users in the netezza system.
_V_TABLE: the table view contains the list of tables created in the netezza performance system.
_V_RELATION_COLUMN: the relation column system catalog view contains the columns available in a table.
_V_TABLE_INDEX: this system catalog contains the information about the
indexes created on table. netezza does not support creating indexes on a table as of now.
_V_OBJECTS: lists the different objects like tables, view, functions etc. available in the netezza.
Example:
SELECT *
FROM _V_RELATION_COLUMN
WHERE
ATTNAME like '%GEO%' --SPECIFY COLUMN NAME
AND type = 'TABLE'
You would access something similar to an information_schema.
Column Name, %COW%', would use % as a wildcard...gathering any column that has 'COW' in the name
SELECT *
FROM _V_SYS_COLUMNS
WHERE
COLUMN_NAME like '%COW%'
AND TABLE_SCHEMA = 'DEV'
ORDER BY TABLE_NAME
;

SQL Server 2008 - SELECT query

I have a database with over a 150 tables. I need to be able to find every table that has a column called EmployeeID. Is there a way for me to find all tables that have this column? It's kind of a long process if I go through each table and try to find if it has that column.
Use INFORMATION_SCHEMA.COLUMNS:
select c.*
from INFORMATION_SCHEMA.COLUMNS c
where column_name = 'EmployeeID';

Find column in separate table

I've got table A with column X. Column X SHOULD exist within table B too, however, the name of table B is unknown to me.
Is there a way of finding table B?
I am using an Oracle database and SQL Developer. I cannot see anything of help in the contraints/dependencies sections of table A. I suspect the relationship between column X and table B is taken care of by the application interacting with the database.
Try with the following:
select *
from dba_tab_columns
where column_name = 'COLUMN_X'
and table_name != 'TABLE_A'
You could even study all procedures, package, triggers, etc using your column, to understand the way they manipulate the data in your column; to find these objects, try:
select NAME, TYPE, OWNER
from dba_source
where upper(text) like '%COLUMN_X%'
DBA_TAB_COLUMNS Table describes columns of all tables,view and clusters in the database. Refer Oracle Documentation. Both DBA_TAB_COLUMNS and ALL_TAB_COLUMNS provide similar information while ALL_TAB_COLUMNS provide info as accessible to the current user
Refer Oracle Documentation -
https://docs.oracle.com/cd/B19306_01/server.102/b14237/statviews_4146.htm#REFRN23277
https://docs.oracle.com/cd/B19306_01/server.102/b14237/statviews_2094.htm#I1020277

How to search a column in multiple tables in SQL Server 2005

There are several tables with many columns and it takes forever to manually find the column I need. How do I search for my column from whatever table it exists in?
You can do:
SELECT COLUMN_NAME, TABLE_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_NAME LIKE '%columnName%'
You can use the sys.columns view and then join to the sys.tables view to get that information.