Searching all tables in database containing specific column - sql

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'

Related

how to find column names which has particular value in snowflake for a particular schema. The schema may have more than 300 tables

Basically search for all the columns which has a specific value in multiples tables in a schema
In Snowflake, there is a 'COLUMNS' view which has this information. You can use the following commands:
use <Database_Name>;
select
column_name
from
information_schema.columns
where
table_schema='<schema_name>'
and column_name like '%value%'

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
;

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

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';

In Oracle, how do you search a tables' column-names?

I have a large table with over 50 columns. And I would like to search those columns for a particular word. How do I do this in Oracle ?
thanks
You can use the following:
select COLUMN_NAME from ALL_TAB_COLUMNS
where TABLE_NAME='your_table_name' and COLUMN_NAME like '%whatever_word_required%';
Explanation: ALL_TAB_COLUMNS describes the columns of the tables, views, and clusters accessible to the current user. So from all the tables, since you want to search in a particular table so give your table-name in the query and specify the criteria for columns using the LIKE.
Say if your table name is "Table1" and column-name you are trying to search is "Employee", so the query becomes:
select COLUMN_NAME from ALL_TAB_COLUMNS
where TABLE_NAME='Table1' and COLUMN_NAME like '%Employee%';
For reference see the Oracle Docs

How do I list all the column names in Netezza?

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
;