- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to identify a column with its existence in all the tables with MySQL?
To identify a column name, use INFORMATION_SCHEMA.COLUMNS in MySQL. Here’s the syntax −
select table_name,column_name from INFORMATION_SCHEMA.COLUMNS where table_schema = SCHEMA() andcolumn_name='anyColumnName';
Let us implement the above query in order to identify a column with its existence in all tables. Here, we are finding the existence of column EmployeeAge −
mysql> select table_name,column_name FROM INFORMATION_SCHEMA.COLUMNS WHERE table_schema = SCHEMA() AND column_name='EmployeeAge';
This will produce the following output displaying the tables with specific column “EmployeeAge” −
+---------------+-------------+ | TABLE_NAME | COLUMN_NAME | +---------------+-------------+ | demotable1153 | EmployeeAge | | demotable1297 | EmployeeAge | | demotable1303 | EmployeeAge | | demotable1328 | EmployeeAge | | demotable1378 | EmployeeAge | | demotable1530 | EmployeeAge | | demotable1559 | EmployeeAge | | demotable1586 | EmployeeAge | | demotable1798 | EmployeeAge | | demotable1901 | EmployeeAge | | demotable511 | EmployeeAge | | demotable912 | EmployeeAge | +---------------+-------------+ 12 rows in set (0.00 sec)
To prove, let us check the description of any of the above table −
mysql> desc demotable1153;
This will produce the following output displaying existence of EmployeeAge column in demotable1153 −
+--------------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +--------------+-------------+------+-----+---------+----------------+ | EmployeeId | int(11) | NO | PRI | NULL | auto_increment | | EmployeeName | varchar(40) | YES | MUL | NULL | | | EmployeeAge | int(11) | YES | | NULL | | +--------------+-------------+------+-----+---------+----------------+ 3 rows in set (0.00 sec)
- Related Articles
- How to find tables with a specific column name in MySQL?
- How to display all the tables in MySQL with a storage engine?
- How to display all tables in MySQL with InnoDB storage engine?
- How to GRANT SELECT ON all tables in all databases on a server with MySQL?
- How to combine two tables and add a new column with records in MySQL?
- How can I check the character set of all the tables along with column names in a particular MySQL database?
- How to subtract the same amount from all values in a column with MySQL?
- Concatenate all the columns in a single new column with MySQL
- Use UNION ALL to insert records in two tables with a single query in MYSQL
- MySQL query to calculate sum from 5 tables with a similar column named “UP”?
- How MySQL CONCAT() function, applied to the column/s of a table, can be combined with the column/s of other tables?
- Get all the records with two different values in another column with MySQL
- How to display all the MySQL tables in one line?
- Concatenate two tables in MySQL with a condition?
- Find a specific column in all the tables in a database?

Advertisements