- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- 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 do I detect if a table exist in MySQL?
To detect the existence of a table, use the concept of INFORMATION_SCHEMA.TABLES. Following is the syntax −
select table_name from information_schema.tables where table_schema=database() and table_name=yourTableName;
To understand the above syntax, let us create a table −
mysql> create table DemoTable2032 -> ( -> ClientId int, -> ClientName varchar(20), -> ClientAge int, -> ClientCountryName varchar(20) -> ); Query OK, 0 rows affected (1.07 sec)
Here is the query to detect if a table exist in a database −
mysql> select table_name from information_schema.tables -> where table_schema=database() -> and table_name='DemoTable2032';
This will produce the following output −
+---------------+ | TABLE_NAME | +---------------+ | demotable2032 | +---------------+ 1 row in set (0.00 sec)
Advertisements