
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
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)
- Related Articles
- How to check if a column exist in a MySQL table?
- How do I detect if the ON UPDATE event fired with query in MySQL?
- Different methods to check if a MySQL table exist?
- How do I alter a MySQL table column defaults?
- Check if table exist without using “select from” in MySQL?
- How do I know if a MySQL table is using myISAM or InnoDB Engine?
- How to check if a table exists in MySQL and create if it does not already exist?
- How do I list all the columns in a MySQL table?
- How do I show unique constraints of a table in MySQL?
- How do I clone the structure of a table in MySQL?
- How do I add a check constraint to a table in MySQL?
- How do I remove a uniqueness constraint from a MySQL table?
- How do I view the auto_increment value for a table in MySQL?
- How to select from MySQL table A that does not exist in table B?
- How do I show the schema of a table in a MySQL database?

Advertisements